[BUG] document_and_reload() fails when R/app_config.R contains an empty argument

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

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
tooling

Research direction

Start in R/reload.R at check_name_consistency(), around the codetools::walkCode() loop near line 90, and read how setwd() is used before that. Reproduce with the short script in the issue, then skip missing arguments in the loop and add an on.exit(setwd(...), add = TRUE) after the directory change. Done means an R/app_config.R containing df[, 1] no longer errors and getwd() is back in the original directory.

Written by the indexing model from the issue text.

Description

bug

Describe the bug

document_and_reload() fails as soon as R/app_config.R contains a call with an empty argument, e.g. df[, 1].

check_name_consistency() walks the code with for (e in as.list(expr)[-1L]) codetools::walkCode(e, w) (R/reload.R#L90). When an argument is empty, e is a missing argument and walkCode() errors.

Because check_name_consistency() uses setwd() without on.exit(), the working directory is also left inside the project after the error.

To Reproduce

library(golem)
p <- file.path(
  tempdir(),
  "cncapp"
)
create_golem(
  p,
  open = FALSE,
  check_name = FALSE
)
write(
  "first_col <- function(df) df[, 1]",
  file.path(
    p,
    "R",
    "app_config.R"
  ),
  append = TRUE
)
setwd(tempdir())
res <- try(document_and_reload(golem_wd = p))
getwd() == p

Output:

Error in w$call(e, w) : argument "e" is missing, with no default
[1] TRUE

Expected behavior

Empty arguments are skipped, the package is documented and reloaded, and the working directory is restored.

Additional context

Suggested fix (same pattern as {codetools}' default walker):

for (e in as.list(expr)[-1L]) {
  if (!missing(e)) {
    codetools::walkCode(
      e,
      w
    )
  }
}

plus on.exit(setwd(old_dir), add = TRUE) right after the setwd() call.

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.