Skip to content

Commit 07a297e

Browse files
committed
fix: make cli_inform suppressible in a simpler way
1 parent 7d0eddd commit 07a297e

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

R/cache.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ cache_environ$epidatr_cache <- NULL
9090
#' variable is `EPIDATR_CACHE_LOGFILE`.
9191
#' @param confirm whether to confirm directory creation. default is `TRUE`;
9292
#' should only be set in non-interactive scripts
93+
#' @param startup indicates whether the function is being called on
94+
#' startup. Affects suppressability of the messages. Default is `FALSE`.
9395
#' @return [`NULL`] no return value, all effects are stored in the package
9496
#' environment
9597
#' @seealso [`clear_cache`] to delete the old cache while making a new one,
@@ -102,7 +104,8 @@ set_cache <- function(cache_dir = NULL,
102104
days = NULL,
103105
max_size = NULL,
104106
logfile = NULL,
105-
confirm = TRUE) {
107+
confirm = TRUE,
108+
startup = FALSE) {
106109
if (is.null(cache_dir)) {
107110
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = rappdirs::user_cache_dir("R", version = "epidatr"))
108111
} else if (is.null(cache_dir)) {
@@ -170,11 +173,12 @@ set_cache <- function(cache_dir = NULL,
170173

171174
# this is effectively a startup message, and for some reason, cli_inform doesn't support start suppression, so we're on our own
172175
# https://github.com/r-lib/cli/issues/589 when this closes we can go back.
173-
msg <- "{cli::symbol$warn} epidatr cache is being used (set env var EPIDATR_USE_CACHE=FALSE if not intended).
174-
{cli::symbol$info} The cache directory is {cache_dir}.
175-
{cli::symbol$info} The cache will be cleared after {days} day{ifelse(days>1,'s','')} and will be pruned if it exceeds {max_size} MB.
176-
{cli::symbol$info} The log of cache transactions is stored at {file.path(cache_dir, logfile)}."
177-
rlang::inform(cli::format_inline(msg), class = "packageStartupMessage")
176+
cli::cli_inform(c(
177+
"!" = "epidatr cache is being used (set env var EPIDATR_USE_CACHE=FALSE if not intended).",
178+
"i" = "The cache directory is {cache_dir}.",
179+
"i" = "The cache will be cleared after {days} day{ifelse(days>1,'s','')} and will be pruned if it exceeds {max_size} MB.",
180+
"i" = "The log of cache transactions is stored at {file.path(cache_dir, logfile)}."
181+
), class = if (startup) "packageStartupMessage" else NULL)
178182
}
179183

180184
#' Manually reset the cache, deleting all currently saved data and starting afresh

R/epidatr-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
cache_environ$use_cache <- Sys.getenv("EPIDATR_USE_CACHE", unset = FALSE)
1212
cache_environ$use_cache <- (cache_environ$use_cache == "TRUE")
1313
if (cache_environ$use_cache) {
14-
set_cache()
14+
set_cache(startup = TRUE)
1515
}
1616
}

man/clear_cache.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/set_cache.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)