Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ importFrom(purrr,partial)
importFrom(purrr,pmap)
importFrom(purrr,pwalk)
importFrom(purrr,when)
importFrom(rlang,"%||%")
importFrom(rlang,abort)
importFrom(rlang,is_empty)
importFrom(rlang,is_installed)
Expand Down
13 changes: 7 additions & 6 deletions R/ui-caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cache_clear <- function(cache_name = NULL, ask = TRUE) {
#'
#' @section Using a cache for styler in CI/CD:
#' If you want to set up caching in a CI/CD pipeline, we suggest to set the
#' `{R.cache}` root path to a directory for which you have the cache enabled as
#' `{R.cache}` root path to a directory for which you have the cache enabled.
#' This can often be set in config files of CI/CD tools, e.g. see the
#' [Travis documentation on caching](https://docs.travis-ci.com/user/caching).
#'
Expand Down Expand Up @@ -86,6 +86,7 @@ cache_info <- function(cache_name = NULL, format = "both") {
activated = cache_is_activated(cache_name),
stringsAsFactors = FALSE
)

if (any(c("lucid", "both") == format)) {
cat(
"Size:\t\t", tbl$size, " bytes (", tbl$n, " cached expressions)",
Expand All @@ -111,23 +112,23 @@ cache_info <- function(cache_name = NULL, format = "both") {
#' @inheritParams cache_clear
#' @param verbose Whether or not to print an informative message about what the
#' function is doing.
#'
#' @importFrom rlang "%||%"
#' @family cache managers
#' @export
cache_activate <- function(cache_name = NULL,
verbose = !getOption("styler.quiet", FALSE)) {
if (!is.null(cache_name)) {
options("styler.cache_name" = cache_name)
} else {
options("styler.cache_name" = styler_version)
}
options("styler.cache_name" = cache_name %||% styler_version)
path <- cache_find_path(cache_name)

if (verbose) {
cat(
"Using cache ", cache_get_name(), " at ",
path, ".\n",
sep = ""
)
}

invisible(path)
}

Expand Down
26 changes: 14 additions & 12 deletions R/utils-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ is_cached <- function(text,
#' @param more_specs A named vector coercible to character that determines the
#' styling but are style guide independent, such as `include_roxygen_examples`
#' or `base_indention`.
#'
#' @details
#' We need to compare:
#'
Expand All @@ -64,6 +65,7 @@ is_cached <- function(text,
#' see `as.character(list(purrr::partial(sum, x = 4)))`. For that reason,
#' all arguments passed to a `purrr::partial()` call must be put in the
#' style guide under `more_specs_style_guide`.
#'
#' @section Experiments:
#'
#' There is unexplainable behavior in conjunction with hashing and
Expand All @@ -84,6 +86,7 @@ is_cached <- function(text,
#' overwritten / rebased by now) contains a reprex. Otherwise, search for
#' 43219ixmypi in commit messages and restore this commit to reproduce the
#' behavior.
#'
#' @examples
#' add <- function(x, y) {
#' x + y
Expand Down Expand Up @@ -123,13 +126,16 @@ cache_find_path <- function(cache_name = NULL) {
#' @keywords internal
cache_is_activated <- function(cache_name = NULL) {
current_cache <- cache_get_name()

if (is.null(cache_name)) {
!is.null(current_cache)
} else if (!is.null(current_cache)) {
cache_name == current_cache
} else {
FALSE
return(!is.null(current_cache))
}

if (!is.null(current_cache)) {
return(cache_name == current_cache)
}

return(FALSE)
}

#' Cache text
Expand Down Expand Up @@ -186,13 +192,9 @@ cache_get_name <- function() {
getOption("styler.cache_name")
}

cache_get_or_derive_name <- function(cache_name) {
if (is.null(cache_name)) {
cache_name <- cache_get_name()
if (is.null(cache_name)) {
cache_name <- styler_version
}
}
cache_get_or_derive_name <- function(cache_name = NULL) {
cache_name <- cache_name %||% cache_get_name()
cache_name <- cache_name %||% styler_version
cache_name
}

Expand Down
2 changes: 1 addition & 1 deletion man/caching.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.