Summary
While testing the documented persistent-cache workflow, I found that when EPIDATR_USE_CACHE=TRUE is set and EPIDATR_CACHE_DIR points at a directory that does not exist, .onLoad() calls set_cache(startup = TRUE) with the default confirm = TRUE, which runs an interactive readline() prompt during package load. In a non-interactive session (Rscript, Rmd render, CI) there is no terminal to answer, so loading the package fails or wedges inside library(epidatr) — a session-crash path under a documented configuration. I think .onLoad should not prompt at all: create the directory silently (with a message) or disable caching with a startup message.
Evidence (dev tip 87b10e1; identical on main)
R/epidatr-package.R:22-24:
if (cache_environ$use_cache) {
set_cache(startup = TRUE)
}
set_cache()'s confirm defaults to TRUE (R/cache.R:106-113; the @param confirm doc even says it "should only be set in non-interactive scripts"), and the prompt lives at R/cache.R:146-168:
if (confirm) {
user_input <- readline(glue::glue(
"there is no directory at {cache_dir}; the cache will be turned off until a ",
"viable directory has been set. Create one? (yes|no(default)) "
))
...
Maintainer-runnable repro
EPIDATR_USE_CACHE=TRUE EPIDATR_CACHE_DIR=/nonexistent Rscript -e 'library(epidatr)'
In a non-interactive session the readline() prompt has no usable stdin, so package load aborts (the exact failure mode varies by R version — readline() errors, or reads EOF and the prompt loop then fails on the empty input). The package never loads either way, which is the bug.
Expected vs. actual
- Expected: a missing cache directory at load time degrades gracefully — cache is created (non-interactively) or disabled with a
packageStartupMessage; library(epidatr) always succeeds.
- Actual:
library() itself fails in Rscript/Rmd/render pipelines — the environments where .Renviron-configured caches are most commonly used.
Suggested fix
Either:
- Pass
confirm = FALSE at startup — set_cache(startup = TRUE, confirm = FALSE) — so the directory is created without prompting and any failure degrades to "cache disabled" with a message; or
- Gate the prompt on
interactive() inside set_cache() (non-interactive → skip prompting, disable with a message).
Optionally also document in ?set_cache that startup never prompts.
I checked for prior reports (open/closed issues about EPIDATR_USE_CACHE, startup, or non-interactive failures — #193/#198 are about cache notifications/env-var docs) and found none covering this.
Summary
While testing the documented persistent-cache workflow, I found that when
EPIDATR_USE_CACHE=TRUEis set andEPIDATR_CACHE_DIRpoints at a directory that does not exist,.onLoad()callsset_cache(startup = TRUE)with the defaultconfirm = TRUE, which runs an interactivereadline()prompt during package load. In a non-interactive session (Rscript, Rmd render, CI) there is no terminal to answer, so loading the package fails or wedges insidelibrary(epidatr)— a session-crash path under a documented configuration. I think.onLoadshould not prompt at all: create the directory silently (with a message) or disable caching with a startup message.Evidence (dev tip 87b10e1; identical on
main)R/epidatr-package.R:22-24:set_cache()'sconfirmdefaults toTRUE(R/cache.R:106-113; the@param confirmdoc even says it "should only be set in non-interactive scripts"), and the prompt lives atR/cache.R:146-168:Maintainer-runnable repro
EPIDATR_USE_CACHE=TRUE EPIDATR_CACHE_DIR=/nonexistent Rscript -e 'library(epidatr)'In a non-interactive session the
readline()prompt has no usable stdin, so package load aborts (the exact failure mode varies by R version —readline()errors, or reads EOF and the prompt loop then fails on the empty input). The package never loads either way, which is the bug.Expected vs. actual
packageStartupMessage;library(epidatr)always succeeds.library()itself fails in Rscript/Rmd/render pipelines — the environments where.Renviron-configured caches are most commonly used.Suggested fix
Either:
confirm = FALSEat startup —set_cache(startup = TRUE, confirm = FALSE)— so the directory is created without prompting and any failure degrades to "cache disabled" with a message; orinteractive()insideset_cache()(non-interactive → skip prompting, disable with a message).Optionally also document in
?set_cachethat startup never prompts.I checked for prior reports (open/closed issues about
EPIDATR_USE_CACHE, startup, or non-interactive failures — #193/#198 are about cache notifications/env-var docs) and found none covering this.