Skip to content

Commit

Permalink
Update staticimports (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie authored Feb 28, 2023
1 parent 50d7648 commit 23e41c0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/staticimports.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ system_file <- function(..., package = "base") {
normalizePath(files, winslash = "/")
}

# A wrapper for `system.file()`, which caches the results, because
# `system.file()` can be slow. Note that because of caching, if
# `system_file_cached()` is called on a package that isn't installed, then the
# package is installed, and then `system_file_cached()` is called again, it will
# still return "".
# A wrapper for `system.file()`, which caches the package path because
# `system.file()` can be slow. If a package is not installed, the result won't
# be cached.
system_file_cached <- local({
pkg_dir_cache <- character()

Expand All @@ -101,7 +99,9 @@ system_file_cached <- local({
not_cached <- is.na(match(package, names(pkg_dir_cache)))
if (not_cached) {
pkg_dir <- system.file(package = package)
pkg_dir_cache[[package]] <<- pkg_dir
if (nzchar(pkg_dir)) {
pkg_dir_cache[[package]] <<- pkg_dir
}
} else {
pkg_dir <- pkg_dir_cache[[package]]
}
Expand Down

0 comments on commit 23e41c0

Please sign in to comment.