Skip to contents

Checks if cache folder exists, if not returns an informative message

Usage

tw_check_cache_folder()

Value

If the cache folder exists, returns TRUE. Otherwise throws an error.

Examples


# If cache folder does not exist, it throws an error
tryCatch(tw_check_cache_folder(),
  error = function(e) {
    return(e)
  }
)
#> <error/rlang_error>
#> Error in `tw_check_cache_folder()`:
#> ! Cache folder does not exist.
#>  Set it with `tw_set_cache_folder()` and create it with
#>   `tw_create_cache_folder()`.
#> ---
#> Backtrace:
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5. ─pkgdown:::unwrap_purrr_error(...)
#>   6. └─base::withCallingHandlers(...)
#>   7.         └─purrr::map(...)
#>   8.           └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>   9. ─purrr:::with_indexed_errors(...)
#>  10. └─base::withCallingHandlers(...)
#>  11. purrr:::call_with_cleanup(...)
#>  12.             └─pkgdown (local) .f(.x[[i]], ...)
#>  13. base::withCallingHandlers(...)
#>  14.               └─pkgdown:::data_reference_topic(...)
#>  15.                 └─pkgdown:::run_examples(...)
#>  16.                   └─pkgdown:::highlight_examples(code, topic, env = env)
#>  17.                     └─downlit::evaluate_and_highlight(...)
#>  18.                       └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  19.                         └─evaluate:::evaluate_call(...)
#>  20. ─evaluate (local) timing_fn(...)
#>  21. ─evaluate (local) handle(...)
#>  22. └─base::try(f, silent = TRUE)
#>  23. └─base::tryCatch(...)
#>  24. └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  25. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  26. └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>  27. ─base::withCallingHandlers(...)
#>  28. ─base::withVisible(...)
#>  29.                           └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  30.                             └─base::eval(expr, envir, enclos)
#>  31.                               └─base::eval(expr, envir, enclos)
#>  32. ─base::tryCatch(...)
#>  33. └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  34. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  35. └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>  36.                                 └─tidywikidatar::tw_check_cache_folder()

# Create cache folder
tw_set_cache_folder(path = fs::path(
  tempdir(),
  "tw_cache_folder"
))
tw_create_cache_folder(ask = FALSE)

tw_check_cache_folder()
#> [1] TRUE