Skip to content

Commit

Permalink
Merge branch 'release/0.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Apr 30, 2021
2 parents 8248c82 + 3368973 commit 2a543be
Show file tree
Hide file tree
Showing 19 changed files with 602 additions and 432 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#----------------------------
^.svn
^.git
^.github
^.make
INSTALL[.]md
OVERVIEW[.]md
Expand Down
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
58 changes: 58 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on: [push, pull_request]

name: R-CMD-check

jobs:
R-CMD-check:
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
if: "! contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ${{ matrix.config.os }}

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'devel' }
- {os: windows-latest, r: 'release' }
- {os: macOS-latest, r: 'devel' }
- {os: macOS-latest, r: 'release' }
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ matrix:
- _R_CHECK_LENGTH_1_CONDITION_=true
- _R_CHECK_LENGTH_1_LOGIC2_=true
- _R_CLASS_MATRIX_ARRAY_=true
- os: osx
r: oldrel
- os: osx
r: release
- os: linux
r: release
r_check_args: --no-build-vignettes --no-codoc --no-examples --no-tests --no-manual --ignore-vignettes
Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: R.cache
Version: 0.14.0
Version: 0.15.0
Depends:
R (>= 2.14.0)
Imports:
utils,
R.methodsS3 (>= 1.7.1),
R.oo (>= 1.23.0),
R.utils (>= 2.8.0),
R.methodsS3 (>= 1.8.1),
R.oo (>= 1.24.0),
R.utils (>= 2.10.1),
digest (>= 0.6.13)
Title: Fast and Light-Weight Caching (Memoization) of Objects and Results to Speed Up Computations
Authors@R: c(person("Henrik", "Bengtsson", role=c("aut", "cre", "cph"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ importFrom("R.utils", "removeDirectory")
importFrom("R.utils", "touchFile")
importFrom("utils", "compareVersion")
importFrom("utils", "packageVersion")
importFrom("utils", "file_test")
importFrom("utils", "menu")
importFrom("digest", "digest")

## Manually adjusted
Expand Down
19 changes: 18 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Package: R.cache
================

Version: 0.15.0 [2021-04-27]

SIGNIFICANT CHANGES:

* The location of the root cache folder as introduced in R.cache 0.14.0 has
been updated to match that of tools::R_user_dir(), which was introduced
in R 4.0.0. On Linux, this was already the case in R.cache 0.14.0,
whereas on macOS and MS Windows, the folder locations have changed
slightly. If an old cache folder location is detected, then the user will
be queried what action to take, i.e. abort, ignore the old folder, remove
the old folder, or move the old folder to the new location. In
non-interactive mode, the default action is always to ignore.

* The package will no longer ask for permission to create the cache folder
as long as the cache folder is compatible with tools::R_user_dir().


Version: 0.14.0 [2019-12-05]

SIGNIFICANT CHANGES:
Expand All @@ -13,7 +30,7 @@ SIGNIFICANT CHANGES:
On modern versions of Microsoft Windows, environment variables such
as 'LOCALAPPDATA' will be used, which typically resolves to
'%USERPROFILE%/AppData/Local, e.g. 'C:/Users/alice/AppData/Local'.
If R.cache fails find a proper OS-specific cache folder, it will fall
If R.cache fails to find a proper OS-specific cache folder, it will fall
back to using ~/.Rcache as previously done.
Importantly, if ~/.Rcache already exists, then that will be used by
default. This is done in order to not lose previously cached files.
Expand Down
124 changes: 118 additions & 6 deletions R/getOSCacheRootPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ getWindowsLocalAppData <- function() {
}


findOSCachePath <- function() {
os <- getOS()

findOSCachePath_0.14.0 <- function(os = getOS()) {
root <- switch(os,
windows = getWindowsLocalAppData(),
macos = "~/Library/Caches",
unix = Sys.getenv("XDG_CACHE_HOME", "~/.cache"),
macos = file.path("~", "Library", "Caches"),
unix = Sys.getenv("XDG_CACHE_HOME", file.path("~", ".cache")),
NA_character_
)

Expand All @@ -49,9 +47,123 @@ findOSCachePath <- function() {
path <- c("~", ".Rcache")
}

path <- do.call(file.path, args = as.list(path))
do.call(file.path, args = as.list(path))
}

findOSCachePath_0.15.0 <- if (getRversion() >= "4.0.0") {
function(os = getOS()) {
# message("findOSCachePath_0.15.0() ...")
# on.exit(message("findOSCachePath_0.15.0() ... done"))

# message("os=", os)
# message("getOS()=", getOS())
if (os != getOS()) {
if (os == "macos") {
tracer <- quote(Sys.info <- function() c(sysname = "Darwin"))
} else {
tracer <- quote(.Platform <- list(OS.type = os))
}
message("- trace(tools::R_user_dir, tracer = tracer) ...")
trace(tools::R_user_dir, tracer = tracer)
message("- trace(tools::R_user_dir, tracer = tracer) ... done")
on.exit(untrace(tools::R_user_dir))
}
tools::R_user_dir(.packageName, which = "cache")
}
} else function(os = getOS()) {
path <- Sys.getenv("R_USER_CACHE_DIR", NA_character_)
if (is.na(path)) path <- Sys.getenv("XDG_CACHE_HOME", NA_character_)
if (is.na(path)) {
path <- switch(os,
windows = file.path(Sys.getenv("LOCALAPPDATA"), "R", "cache"),
macos = file.path("~", "Library", "Caches", "org.R-project.R"),
unix = file.path("~", ".cache")
)
}
file.path(path, "R", .packageName)
}


#' @importFrom utils file_test menu
findOSCachePath <- function(os = getOS(), action = c("query", "error", "warn", "remove", "move", "ignore")) {
rm_folder_if_empty <- function(path) {
if (!file_test("-d", path)) return(FALSE)
content <- dir(path = path, all.files = TRUE)
content <- setdiff(content, c(".", ".."))
has_README <- ("README.md" %in% content)
if (has_README) content <- setdiff(content, "README.md")
if (length(content) > 0) return(TRUE)
unlink(path, recursive = has_README)
file_test("-d", path)
}

# message("findOSCachePath() ...")
# on.exit(message("findOSCachePath() ... done"))

action <- match.arg(action)

if (action == "query") {
## Cannot query user?
if (!interactive() || isTRUE(getOption("R.cache.onLoad", FALSE))) {
action <- "ignore"
}
}

path <- findOSCachePath_0.15.0(os = os)
path <- normalizePath(path, mustWork = FALSE)

## Is there another, old cache folder? Can we migrate it?
if (action != "ignore") {
path_old <- findOSCachePath_0.14.0(os = os)
path_old <- normalizePath(path_old, mustWork = FALSE)
exists_old <- rm_folder_if_empty(path_old)
exists <- rm_folder_if_empty(path)
if (path != path_old && exists_old) {
if (action == "query") {
choices <- c(
"Abort",
"Ignore old R.cache folder",
"Remove old R.cache folder",
if (!exists) "Try to move it to the new location"
)
repeat {
ans <- menu(choices, title = "What to do with old non-empty R.cache folder?")
if (ans != 0L) break
}
action <- c("error", "warn", "remove", "move")[ans]
}
if (action == "remove") {
if (exists_old) {
unlink(path_old, recursive = TRUE)
exists_old <- file_test("-d", path_old)
if (exists_old) {
stop("Failed to remove all of folder: ", sQuote(path_old))
}
}
} else if (action == "move") {
## Can we move the whole folder as-is?
if (!exists) {
file.rename(path_old, path)
exists <- file_test("-d", path)
exists_old <- file_test("-d", path_old)
if (!exists || exists_old) {
stop(sprintf("Failed to move folder: %s (%s) -> %s (%s)",
sQuote(path_old), if (exists_old) "still exists" else "gone",
sQuote(path), if (exists) "exists" else "missing"))
}
} else {
action <- "error"
}
}

if (action %in% c("error", "warn")) {
msg <- sprintf("There is an non-empty old-style R.cache folder that is no longer used. To reuse its content, move files and subfolders from %s to %s", sQuote(path_old), sQuote(path))
if (action == "error") stop(msg)
warning(msg, immediate. = TRUE)
}
}
} ## if (action != "ignore")

path
}

Expand Down
67 changes: 67 additions & 0 deletions R/queryRCmdCheck.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
queryRCmdCheck <- function(...) {
evidences <- list()

# Memoization
evidences[["R_CMD_CHECK"]] <- isTRUE(as.logical(Sys.getenv("R_CMD_CHECK")))

# Command line arguments
args <- commandArgs()
evidences[["vanilla"]] <- is.element("--vanilla", args)

# Check the working directory; any components containing <pkg>.Rcheck/tests
evidences[["pwd"]] <- FALSE
path <- getwd()
last_path <- ""
while (path != last_path) {
last_path <- path
if (basename(path) == "tests") {
if (grepl(".+[.]Rcheck$", dirname(path))) {
evidences[["pwd"]] <- TRUE
break
}
}
path <- dirname(path)
}

# Is 'R CMD check' checking examples?
evidences[["examples"]] <- is.element("CheckExEnv", search())


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Conclusions
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if (evidences$R_CMD_CHECK) {
res <- "R_CMD_CHECK"
} else if (!evidences[["vanilla"]]) {
res <- "notRunning"
} else if (evidences[["examples"]]) {
res <- "checkingExamples"
} else if (evidences[["pwd"]]) {
res <- "checkingTests"
} else {
res <- "notRunning"
}

# Make it stick
if (res != "notRunning") {
Sys.setenv(R_CMD_CHECK = "true")
}

attr(res, "evidences") <- evidences

if (isTRUE(as.logical(Sys.getenv("R_R_CACHE_DEBUG")))) {
file <- file.path("~", ".cache", "R", sprintf("R.cache-%d.log", Sys.getpid()))
dir.create(dirname(file), recursive = TRUE, showWarnings = FALSE)
cat(sprintf("Call: %s\n", paste(commandArgs(), collapse = " ")), file = file, append = TRUE)
cat(sprintf("PID: %s\n", Sys.getpid()), file = file, append = TRUE)
cat(sprintf("pwd: %s\n", getwd()), file = file, append = TRUE)
cat(sprintf("search(): %s\n", paste(sQuote(search()), collapse = ", ")), file = file, append = TRUE)
cat(sprintf("R_CMD_CHECK: %s\n", sQuote(Sys.getenv("R_CMD_CHECK", NA_character_))), file = file, append = TRUE)
cat(sprintf("queryRCmdCheck(): %s\n", sQuote(res)), file = file, append = TRUE)
}

res
}


inRCmdCheck <- function() (queryRCmdCheck() != "notRunning")
7 changes: 2 additions & 5 deletions R/setupCacheRootPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ setMethodS3("setupCacheRootPath", "default", function(defaultPath=NULL, ...) {
# unless the default directory exists, ...
osDefaultPath <- getDefaultCacheRootPath(NULL)
defaultPath <- getDefaultCacheRootPath(defaultPath)
if (isDirectory(defaultPath)) {
if (isDirectory(defaultPath) || identical(defaultPath, osDefaultPath)) {
rootPath <- defaultPath
} else if (interactive()) {
# or we cn ask the user to confirm the default path...
prompt <- "The R.cache package needs to create a directory that will hold cache files."
if (identical(defaultPath, osDefaultPath)) {
prompt <- c(prompt, "It is convenient to use ", sQuote(osDefaultPath), "because it follows the standard on your operating system and it remains also after restarting R.")
}
prompt <- "The R.cache package needs to create a non-standard directory that will hold cache files."
prompt <- c(prompt, sprintf("Do you wish to create the '%s' directory? If not, a temporary directory (%s) that is specific to this R session will be used.", defaultPath, rootPath))
prompt <- paste(prompt, collapse=" ")
tryCatch({
Expand Down
Loading

0 comments on commit 2a543be

Please sign in to comment.