Skip to content

.onLoad prompts for cache-directory creation via readline() — library(epidatr)` fails in non-interactive sessions (Rscript/Rmd/render pipelines) when the configured directory is missing #401

Description

@docxology

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:

  1. 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
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions