[BUG] add_module() doesn't sanitize `name` and can generate an unparsable file

Open Beginner friendly
#1,259 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r

Research direction

Read R/modules_fn.R around line 67, where add_module() calls mod_remove(file_path_sans_ext(name)), and compare with how add_fct()/add_utils()/add_r6() apply sanitize_r_name() before building the file name and the ui/server symbols. Apply the same sanitization in add_module() and at the use_module_test() path near L515, then reproduce with the issue's tempdir() script to confirm mod_my_module.R parses. Running the package tests for module creation shows whether anything else depended on the old naming.

Written by the indexing model from the issue text.

Description

bug

Describe the bug

add_fct(), add_utils() and add_r6() clean their name with sanitize_r_name(), but add_module() doesn't. A module name containing a space or another non-syntactic character generates an R file that cannot be parsed, which then breaks document_and_reload() / devtools::check().

To Reproduce

library(golem)
p <- file.path(
  tempdir(),
  "modapp"
)
create_golem(
  p,
  open = FALSE,
  check_name = FALSE
)
add_module(
  "my module",
  golem_wd = p,
  open = FALSE
)
add_fct(
  "my fct",
  golem_wd = p,
  open = FALSE
)
list.files(
  file.path(
    p,
    "R"
  )
)
parse(
  file.path(
    p,
    "R",
    "mod_my module.R"
  )
)

Output:

[1] "app_config.R"    "app_server.R"    "app_ui.R"        "fct_my_fct.R"   
[5] "mod_my module.R" "run_app.R"      
Error in parse(file.path(p, "R", "mod_my module.R")) : 
  /tmp/RtmpfWCFEx/modapp/R/mod_my module.R:10:8: unexpected symbol
9: #' @importFrom shiny NS tagList 
10: mod_my module_ui
           ^

Expected behavior

Either add_module("my module") creates mod_my_module.R with mod_my_module_ui() / mod_my_module_server() (consistent with add_fct()), or it errors early with an explicit message.

Additional context

The fix probably belongs next to mod_remove(file_path_sans_ext(name)) in R/modules_fn.R#L67. use_module_test() (L515) uses the same pattern.

session info

R 4.3.3, Ubuntu 24.04, {golem} master (9938a41, version 1.0.1).


Generated by Claude Code

Dominant language
R
Stars
947
Forks
135
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ThinkR-open/golem

All issues in ThinkR-open/golem

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.