[BUG] amend_golem_config() drops `!expr` tags after the first expression of a section
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The tagging happens in add_expr_tag() in R/golem-yaml-utils.R, which sets the !expr attribute only on tag[[1]]; find_and_tag_exprs() in the same file decides which values get tagged. Run the reproduction from the issue and check inst/golem-config.yml afterwards, then confirm that every expression in a section keeps !expr after amend_golem_config(). Done means a test with two or more expressions in one section passes and the written file still has the tags.
Written by the indexing model from the issue text.
Description
Describe the bug
amend_golem_config() (and therefore set_golem_name(), set_golem_version(), set_golem_wd() and fill_desc()) silently turns !expr values into plain strings when a config section contains more than one expression. This is a partial regression of #709.
add_expr_tag() (R/golem-yaml-utils.R#L4-L12) only sets the tag attribute on tag[[1]], so every expression after the first one in a section loses its !expr tag. YAML comments are also dropped by yaml::write_yaml().
To Reproduce
library(golem)
p <- file.path(
tempdir(),
"yamlapp"
)
create_golem(
p,
open = FALSE,
check_name = FALSE
)
cfg <- file.path(
p,
"inst",
"golem-config.yml"
)
write(
" db_host: !expr Sys.getenv('DB_HOST', 'localhost')",
cfg,
append = TRUE
)
amend_golem_config(
key = "my_key",
value = "my_value",
golem_wd = p
)
cat(
readLines(cfg),
sep = "\n"
)
Before:
dev:
golem_wd: !expr golem::pkg_path()
db_host: !expr Sys.getenv('DB_HOST', 'localhost')
After:
dev:
golem_wd: !expr golem::pkg_path()
db_host: Sys.getenv('DB_HOST', 'localhost')
db_host is now the literal string "Sys.getenv('DB_HOST', 'localhost')".
Expected behavior
All !expr values are preserved.
Additional context
Tagging every element fixes the reproducible example above (tested by patching the namespace):
add_expr_tag <- function(
tag
) {
for (i in seq_along(tag)) {
attr(
tag[[i]],
"tag"
) <- "!expr"
}
tag
}
Remaining limitations worth a test: expressions nested deeper than one level are not detected by find_and_tag_exprs() (one-level %in% comparison), and comments are lost on every write.
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 82/100
ThinkR-open/golem#1259 ·
-
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 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 ·