-
Notifications
You must be signed in to change notification settings - Fork 73
Cache styling #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Cache styling #538
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
938c9f9
implement basic caching
lorenzwalthert 94c48ae
cache administration tools
lorenzwalthert f57a7c5
set all options in .onLoad(), do not use the default in getOptions().
lorenzwalthert cc02ccd
don't use cache in general
lorenzwalthert bf658be
handle situation where R.cache is not available.
lorenzwalthert f2a8d2e
assert that the R.cache is installed
lorenzwalthert fc9ec71
drop fs dependency.
lorenzwalthert 4ceb7c5
fix naming.
lorenzwalthert 59168c2
fix R cmd check
lorenzwalthert 219a73c
res-style with stylermd
lorenzwalthert b721904
add more cache manipulators.
lorenzwalthert 3fe9bbd
don't use technical name cache_subdir (as it would be from the R.cach…
lorenzwalthert 6aef9ff
fix spacing.
lorenzwalthert 390d2b4
be consistent: all cache functions start with cache_
lorenzwalthert fa3dc16
also export deactivate
lorenzwalthert 3ff182a
don't read the cache, just check if it exists
lorenzwalthert 1ab8be0
make styling work without R.chache installed.
lorenzwalthert e48b5ec
add line break at end of message.
lorenzwalthert bb52ea0
add action = "abort" as optional.
lorenzwalthert fb98b79
return a default path stlyer/:version instead instead of just styler …
lorenzwalthert 0d0fa92
remove option styler.use_cache. If styler.cache_name is NULL, this is…
lorenzwalthert 43c58c9
also test when R.cache is not installed.
lorenzwalthert 87d782a
add new option "both" for cache_info(), argument "format".
lorenzwalthert b2b4213
outsource logic to get cache name from input, get it from the option …
lorenzwalthert 865c6e8
cache_is_activated() can now return information about a specific cach…
lorenzwalthert 73d0220
random doc update
lorenzwalthert 6fad8c4
improve tests
lorenzwalthert f51c707
add a verbose argument to cache_deactivate
lorenzwalthert 94d5891
split R/ui.R into R/ui-caching.R and R/ui-styling.R
lorenzwalthert 18807d1
test that after clearing a cache, no cache is active.
lorenzwalthert 2f85b12
describe caching.
lorenzwalthert cea1922
cache_activate gains new argument verbose for consistency.
lorenzwalthert 66b276d
tidy description.
lorenzwalthert 8c2c7ed
don't add another style_file that convolutes full text search and "go…
lorenzwalthert 2fc8808
minor fixes and simplification
lorenzwalthert dd19539
assume R_REMOVE_RCACHE is false when not set to true.
lorenzwalthert 2848ac1
make file less nicely styled
lorenzwalthert 6eba449
round values to make tests pass on all plattforms.
lorenzwalthert 3f91267
round two digits
lorenzwalthert fac1558
style with stylermd
lorenzwalthert 346f76b
cache NULL, not the sysdate, which can also be derived from the creat…
lorenzwalthert 813d4e8
add news section on caching.
lorenzwalthert f170c27
adapt test for hashing NULL
lorenzwalthert 90f927a
use the shallow cache only (needs my fork or R.cache).
lorenzwalthert 1b3814d
use R.cache
lorenzwalthert ab3ed59
unrelated wording NEWS
lorenzwalthert 9674200
doc wording
lorenzwalthert fe74f9e
don't o$
lorenzwalthert b1cf70d
derive cache more cheaply
lorenzwalthert f2b16a5
chache size should be 0 with shallow option
lorenzwalthert 427a1c0
move R.cache to suggest as initially thought
lorenzwalthert 2996302
replace cache_derive_name() with constant
lorenzwalthert 9326f44
random roxygenize
lorenzwalthert 0a81566
capsule line break conversion in a function
lorenzwalthert c0e1292
make cache work when text is supplied with embedded line breaks
lorenzwalthert c2c8e63
need pkg qualifier for example with internal function
lorenzwalthert 6993203
some version that seems to work
lorenzwalthert 4f3ab57
make commit to keep reproducible example where hashes of transformers…
lorenzwalthert 172ad9a
document edge cases
lorenzwalthert 5efc656
add test
lorenzwalthert d013cea
again remove xfun reference
lorenzwalthert 4fb19f9
Merge branch 'master' into caching
krlmlr abb204e
Tweaks
krlmlr 36606a2
use upstream R.cache for caching
lorenzwalthert c6c3aff
new documentation roxygen version
lorenzwalthert 6d3cd88
don't cat info on cached
lorenzwalthert 6f15cc8
R.cache version we depend on now on CRAN
lorenzwalthert 1db8262
Merge branch 'master' into caching
lorenzwalthert 0d41f9b
more info
lorenzwalthert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#' Clear the cache | ||
#' | ||
#' Clears the cache that stores which files are already styled. You won't be | ||
#' able to undo this. Note that the file corresponding to the cache (a folder | ||
#' on your file stystem) won't be deleted, but it will be empty after calling | ||
#' `cache_clear`. | ||
#' @param cache_name The name of the styler cache to use. If | ||
#' `NULL`, the option "styler.cache_name" is considered which defaults to | ||
#' the version of styler used. | ||
#' @details | ||
#' Each version of styler has it's own cache by default, because styling is | ||
#' potentially different with different versions of styler. | ||
#' @param ask Whether or not to interactively ask the user again. | ||
#' @family cache managers | ||
#' @export | ||
cache_clear <- function(cache_name = NULL, ask = TRUE) { | ||
assert_R.cache_installation(installation_only = TRUE) | ||
path_cache <- cache_find_path(cache_name) | ||
R.cache::clearCache(path_cache, prompt = ask) | ||
cache_deactivate(verbose = FALSE) | ||
} | ||
|
||
#' Show information about the styler cache | ||
#' | ||
#' Gives information about the cache. Note that the size consumed by the cache | ||
#' will always be displayed as zero because all the cache does is creating an | ||
#' empty file of size 0 bytes for every cached expression. The innode is | ||
#' excluded from this displayed size but negligible. | ||
#' @param cache_name The name of the cache for which to show details. If | ||
#' `NULL`, the active cache is used. If none is active the cache corresponding | ||
#' to the installed styler version is used. | ||
#' @param format Either "lucid" for a summary emitted with [base::cat()], | ||
#' "tabular" for a tabular summary from [base::file.info()] or "both" for | ||
#' both. | ||
#' @family cache managers | ||
#' @export | ||
cache_info <- function(cache_name = NULL, format = "both") { | ||
assert_R.cache_installation(installation_only = TRUE) | ||
rlang::arg_match(format, c("tabular", "lucid", "both")) | ||
path_cache <- cache_find_path(cache_name) | ||
files <- list.files(path_cache, full.names = TRUE) | ||
file_info <- file.info(files) %>% | ||
as_tibble() | ||
tbl <- tibble( | ||
n = nrow(file_info), | ||
size = sum(file_info$size), | ||
last_modified = suppressWarnings(max(file_info$mtime)), | ||
created = file.info(path_cache)$ctime, | ||
location = path_cache, | ||
activated = cache_is_activated(cache_name) | ||
) | ||
if (format %in% c("lucid", "both")) { | ||
cat( | ||
"Size:\t\t", tbl$size, " bytes (", tbl$n, " cached expressions)", | ||
"\nLast modified:\t", as.character(tbl$last_modified), | ||
"\nCreated:\t", as.character(tbl$created), | ||
"\nLocation:\t", path_cache, | ||
"\nActivated:\t", tbl$activated, | ||
"\n", | ||
sep = "" | ||
) | ||
} | ||
if (format == "tabular") { | ||
tbl | ||
} else if (format == "both") { | ||
invisible(tbl) | ||
} | ||
} | ||
|
||
#' Activate or deactivate the styler cache | ||
#' | ||
#' Helper functions to control the behavior of caching. Simple wrappers around | ||
#' [base::options()]. | ||
#' @inheritParams cache_clear | ||
#' @param verbose Whether or not to print an informative message about what the | ||
#' function is doing. | ||
#' @family cache managers | ||
#' @export | ||
cache_activate <- function(cache_name = NULL, verbose = TRUE) { | ||
assert_R.cache_installation(installation_only = TRUE) | ||
if (!is.null(cache_name)) { | ||
options("styler.cache_name" = cache_name) | ||
} else { | ||
options("styler.cache_name" = styler_version) | ||
} | ||
path <- cache_find_path(cache_name) | ||
if (verbose) { | ||
cat( | ||
"Using cache ", cache_get_name(), " at ", | ||
path, ".\n", | ||
sep = "" | ||
) | ||
} | ||
invisible(path) | ||
} | ||
|
||
#' @rdname cache_activate | ||
#' @export | ||
cache_deactivate <- function(verbose = TRUE) { | ||
options("styler.cache_name" = NULL) | ||
|
||
if (verbose) { | ||
cat("Deactivated cache.\n") | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an early return like
if (use_cache) return(text)
?