tests/testthat/helper-cache.R

# Provides test-safe cache locations and options
with_gutenberg_cache <- function(code, type = "persistent") {
  withr::local_options(
    gutenbergr_cache_type = type
  )

  if (type == "persistent") {
    cache_root <- withr::local_tempdir("gutenbergr-test-")

    withr::local_options(
      gutenbergr_base_cache_dir = cache_root
    )

    gutenberg_ensure_cache_dir()
  } else {
    withr::local_options(
      gutenbergr_base_cache_dir = NULL
    )
  }

  force(code)
}

Try the gutenbergr package in your browser

Any scripts or data that you put into this service are public.

gutenbergr documentation built on Jan. 19, 2026, 9:07 a.m.