[BUG] add_module() doesn't sanitize `name` and can generate an unparsable file
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
- Domain
- developer-experience, tooling
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
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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ThinkR-open/golem
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ThinkR-open/golem#1265 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ThinkR-open/golem#1258 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
ThinkR-open/golem#1257 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ThinkR-open/golem#1256 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ThinkR-open/golem#1255 · 4 comments ·
All issues in ThinkR-open/golem
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
leppott/BioMonTools#162 ·
-
publications
Difficulty 1/5 Under an hour Newbie friendliness 85/100
epiforecasts/epiforecasts.github.io#161 ·
Maintainers usually reply within 1 day
-
Label `{sas}` chunk source as `sas` instead of `txt`, so it gets syntax highlightingPossibly taken @michaelmayer2 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
microbiome/OMA#1031 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
furrer-lab/abn#291 · 2 comments ·