diff --git a/NEWS.md b/NEWS.md index 80ed4dc48..ca7165abb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ editor_options: - `parsable-R` hook now gives more context on where and how parsing fails (#423). +- fixed R CMD check issues in devel # precommit v0.3.1 diff --git a/R/roxygen2.R b/R/roxygen2.R index 388c8f65b..2388570f0 100644 --- a/R/roxygen2.R +++ b/R/roxygen2.R @@ -105,7 +105,13 @@ roxygen_assert_additional_dependencies <- function() { e } ) - if (inherits(out, "packageNotFoundError") || ("message" %in% names(out) && grepl("Dependency package(\\(s\\))? .* not available", out$message))) { + if ( + inherits(out, "packageNotFoundError") || + ("message" %in% names(out) && ( + grepl("Dependency package(\\(s\\))? .* not available", out$message) || + grepl("Failed to load", out$message) + )) + ) { # case used in package but not installed rlang::abort(paste0( "The roxygenize hook requires all dependencies of your package to be listed in ", diff --git a/renv.lock b/renv.lock index 224863ff0..261380b91 100644 --- a/renv.lock +++ b/renv.lock @@ -1,6 +1,6 @@ { "R": { - "Version": "4.0.5", + "Version": "4.3.0", "Repositories": [ { "Name": "CRAN", @@ -13,501 +13,337 @@ "Package": "R.cache", "Version": "0.15.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "e92a8ea8388c47c82ed8aa435ed3be50", - "Requirements": [ - "R.methodsS3", - "R.oo", - "R.utils", - "digest" - ] + "Repository": "RSPM", + "Hash": "e92a8ea8388c47c82ed8aa435ed3be50" }, "R.methodsS3": { "Package": "R.methodsS3", "Version": "1.8.2", "Source": "Repository", "Repository": "RSPM", - "Hash": "278c286fd6e9e75d0c2e8f731ea445c8", - "Requirements": [] + "Hash": "278c286fd6e9e75d0c2e8f731ea445c8" }, "R.oo": { "Package": "R.oo", "Version": "1.25.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "a0900a114f4f0194cf4aa8cd4a700681", - "Requirements": [ - "R.methodsS3" - ] + "Hash": "a0900a114f4f0194cf4aa8cd4a700681" }, "R.utils": { "Package": "R.utils", "Version": "2.11.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "a7ecb8e60815c7a18648e84cd121b23a", - "Requirements": [ - "R.methodsS3", - "R.oo" - ] + "Repository": "RSPM", + "Hash": "a7ecb8e60815c7a18648e84cd121b23a" }, "R6": { "Package": "R6", "Version": "2.5.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "470851b6d5d0ac559e9d01bb352b4021", - "Requirements": [] + "Hash": "470851b6d5d0ac559e9d01bb352b4021" }, "Rcpp": { "Package": "Rcpp", "Version": "1.0.8.3", "Source": "Repository", "Repository": "RSPM", - "Hash": "32e79b908fda56ee57fe518a8d37b864", - "Requirements": [] + "Hash": "32e79b908fda56ee57fe518a8d37b864" }, "backports": { "Package": "backports", "Version": "1.4.1", "Source": "Repository", - "Repository": "CRAN", - "Hash": "c39fbec8a30d23e721980b8afb31984c", - "Requirements": [] + "Repository": "RSPM", + "Hash": "c39fbec8a30d23e721980b8afb31984c" }, "brew": { "Package": "brew", "Version": "1.0-7", "Source": "Repository", "Repository": "RSPM", - "Hash": "38875ea52350ff4b4c03849fc69736c8", - "Requirements": [] + "Hash": "38875ea52350ff4b4c03849fc69736c8" }, "callr": { "Package": "callr", "Version": "3.7.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "461aa75a11ce2400245190ef5d3995df", - "Requirements": [ - "R6", - "processx" - ] + "Repository": "RSPM", + "Hash": "461aa75a11ce2400245190ef5d3995df" }, "cli": { "Package": "cli", "Version": "3.3.0", "Source": "Repository", - "Repository": "RSPM", - "Hash": "23abf173c2b783dcc43379ab9bba00ee", - "Requirements": [ - "glue" - ] + "Repository": "CRAN", + "Hash": "23abf173c2b783dcc43379ab9bba00ee" }, "codetools": { "Package": "codetools", "Version": "0.2-18", "Source": "Repository", "Repository": "CRAN", - "Hash": "019388fc48e48b3da0d3a76ff94608a8", - "Requirements": [] + "Hash": "019388fc48e48b3da0d3a76ff94608a8" }, "commonmark": { "Package": "commonmark", "Version": "1.8.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "2ba81b120c1655ab696c935ef33ea716", - "Requirements": [] + "Hash": "2ba81b120c1655ab696c935ef33ea716" }, "cpp11": { "Package": "cpp11", "Version": "0.4.2", "Source": "Repository", - "Repository": "CRAN", - "Hash": "fa53ce256cd280f468c080a58ea5ba8c", - "Requirements": [] + "Repository": "RSPM", + "Hash": "fa53ce256cd280f468c080a58ea5ba8c" }, "crayon": { "Package": "crayon", "Version": "1.5.1", "Source": "Repository", "Repository": "RSPM", - "Hash": "8dc45fd8a1ee067a92b85ef274e66d6a", - "Requirements": [] + "Hash": "8dc45fd8a1ee067a92b85ef274e66d6a" }, "cyclocomp": { "Package": "cyclocomp", "Version": "1.1.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "53cbed70a2f7472d48fb6aef08442f25", - "Requirements": [ - "callr", - "crayon", - "desc", - "remotes", - "withr" - ] + "Hash": "53cbed70a2f7472d48fb6aef08442f25" }, "desc": { "Package": "desc", "Version": "1.4.1", "Source": "Repository", - "Repository": "RSPM", - "Hash": "eebd27ee58fcc58714eedb7aa07d8ad1", - "Requirements": [ - "R6", - "cli", - "rprojroot" - ] + "Repository": "CRAN", + "Hash": "eebd27ee58fcc58714eedb7aa07d8ad1" }, "digest": { "Package": "digest", "Version": "0.6.29", "Source": "Repository", - "Repository": "CRAN", - "Hash": "cf6b206a045a684728c3267ef7596190", - "Requirements": [] + "Repository": "RSPM", + "Hash": "cf6b206a045a684728c3267ef7596190" }, "docopt": { "Package": "docopt", "Version": "0.7.1", "Source": "Repository", - "Repository": "RSPM", - "Hash": "e9eeef7931ee99ca0093f3f20b88e09b", - "Requirements": [] + "Repository": "CRAN", + "Hash": "e9eeef7931ee99ca0093f3f20b88e09b" }, "ellipsis": { "Package": "ellipsis", "Version": "0.3.2", "Source": "Repository", - "Repository": "CRAN", - "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077", - "Requirements": [ - "rlang" - ] + "Repository": "RSPM", + "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077" }, "evaluate": { "Package": "evaluate", "Version": "0.15", "Source": "Repository", "Repository": "RSPM", - "Hash": "699a7a93d08c962d9f8950b2d7a227f1", - "Requirements": [] + "Hash": "699a7a93d08c962d9f8950b2d7a227f1" }, "fansi": { "Package": "fansi", "Version": "1.0.3", "Source": "Repository", "Repository": "RSPM", - "Hash": "83a8afdbe71839506baa9f90eebad7ec", - "Requirements": [] + "Hash": "83a8afdbe71839506baa9f90eebad7ec" }, "fs": { "Package": "fs", "Version": "1.5.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "7c89603d81793f0d5486d91ab1fc6f1d", - "Requirements": [] + "Hash": "7c89603d81793f0d5486d91ab1fc6f1d" }, "git2r": { "Package": "git2r", "Version": "0.30.1", "Source": "Repository", - "Repository": "RSPM", - "Hash": "e0c6a04a3e7b90e64213d09128f74f1b", - "Requirements": [] + "Repository": "CRAN", + "Hash": "e0c6a04a3e7b90e64213d09128f74f1b" }, "glue": { "Package": "glue", "Version": "1.6.2", "Source": "Repository", - "Repository": "RSPM", - "Hash": "4f2596dfb05dac67b9dc558e5c6fba2e", - "Requirements": [] + "Repository": "CRAN", + "Hash": "4f2596dfb05dac67b9dc558e5c6fba2e" }, "here": { "Package": "here", "Version": "1.0.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "24b224366f9c2e7534d2344d10d59211", - "Requirements": [ - "rprojroot" - ] + "Hash": "24b224366f9c2e7534d2344d10d59211" }, "highr": { "Package": "highr", "Version": "0.9", "Source": "Repository", - "Repository": "CRAN", - "Hash": "8eb36c8125038e648e5d111c0d7b2ed4", - "Requirements": [ - "xfun" - ] + "Repository": "RSPM", + "Hash": "8eb36c8125038e648e5d111c0d7b2ed4" }, "hunspell": { "Package": "hunspell", "Version": "3.0.1", "Source": "Repository", "Repository": "RSPM", - "Hash": "3987784c19192ad0f2261c456d936df1", - "Requirements": [ - "Rcpp", - "digest" - ] + "Hash": "3987784c19192ad0f2261c456d936df1" }, "jsonlite": { "Package": "jsonlite", "Version": "1.8.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "d07e729b27b372429d42d24d503613a0", - "Requirements": [] + "Hash": "d07e729b27b372429d42d24d503613a0" }, "knitr": { "Package": "knitr", "Version": "1.39", "Source": "Repository", - "Repository": "CRAN", - "Hash": "029ab7c4badd3cf8af69016b2ba27493", - "Requirements": [ - "evaluate", - "highr", - "stringr", - "xfun", - "yaml" - ] + "Repository": "RSPM", + "Hash": "029ab7c4badd3cf8af69016b2ba27493" }, "lazyeval": { "Package": "lazyeval", "Version": "0.2.2", "Source": "Repository", "Repository": "RSPM", - "Hash": "d908914ae53b04d4c0c0fd72ecc35370", - "Requirements": [] + "Hash": "d908914ae53b04d4c0c0fd72ecc35370" }, "lifecycle": { "Package": "lifecycle", "Version": "1.0.1", "Source": "Repository", - "Repository": "CRAN", - "Hash": "a6b6d352e3ed897373ab19d8395c98d0", - "Requirements": [ - "glue", - "rlang" - ] + "Repository": "RSPM", + "Hash": "a6b6d352e3ed897373ab19d8395c98d0" }, "lintr": { "Package": "lintr", "Version": "3.0.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "1214604176fb93fdcac030fc5d2177d9", - "Requirements": [ - "backports", - "codetools", - "crayon", - "cyclocomp", - "digest", - "glue", - "jsonlite", - "knitr", - "rex", - "xml2", - "xmlparsedata" - ] + "Hash": "1214604176fb93fdcac030fc5d2177d9" }, "magrittr": { "Package": "magrittr", "Version": "2.0.3", "Source": "Repository", - "Repository": "RSPM", - "Hash": "7ce2733a9826b3aeb1775d56fd305472", - "Requirements": [] + "Repository": "CRAN", + "Hash": "7ce2733a9826b3aeb1775d56fd305472" }, "pillar": { "Package": "pillar", "Version": "1.7.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "51dfc97e1b7069e9f7e6f83f3589c22e", - "Requirements": [ - "cli", - "crayon", - "ellipsis", - "fansi", - "glue", - "lifecycle", - "rlang", - "utf8", - "vctrs" - ] + "Hash": "51dfc97e1b7069e9f7e6f83f3589c22e" }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", "Source": "Repository", - "Repository": "CRAN", - "Hash": "01f28d4278f15c76cddbea05899c5d6f", - "Requirements": [] + "Repository": "RSPM", + "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, "pkgload": { "Package": "pkgload", - "Version": "1.2.4", + "Version": "1.3.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "7533cd805940821bf23eaf3c8d4c1735", - "Requirements": [ - "cli", - "crayon", - "desc", - "rlang", - "rprojroot", - "rstudioapi", - "withr" - ] + "Repository": "RSPM", + "Hash": "4b20f937a363c78a5730265c1925f54a" }, "processx": { "Package": "processx", - "Version": "3.6.0", + "Version": "3.6.1", "Source": "Repository", "Repository": "RSPM", - "Hash": "4acae60adac4791e8c8833d8494f270d", - "Requirements": [ - "R6", - "ps" - ] + "Hash": "a11891e28c1f1e5ddd773ba1b8c07cf6" }, "ps": { "Package": "ps", - "Version": "1.7.0", + "Version": "1.7.1", "Source": "Repository", "Repository": "RSPM", - "Hash": "eef74b13f32cae6bb0d495e53317c44c", - "Requirements": [] + "Hash": "8b93531308c01ad0e56d9eadcc0c4fcd" }, "purrr": { "Package": "purrr", "Version": "0.3.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "97def703420c8ab10d8f0e6c72101e02", - "Requirements": [ - "magrittr", - "rlang" - ] + "Hash": "97def703420c8ab10d8f0e6c72101e02" }, "rematch2": { "Package": "rematch2", "Version": "2.1.2", "Source": "Repository", - "Repository": "CRAN", - "Hash": "76c9e04c712a05848ae7a23d2f170a40", - "Requirements": [ - "tibble" - ] + "Repository": "RSPM", + "Hash": "76c9e04c712a05848ae7a23d2f170a40" }, "remotes": { "Package": "remotes", "Version": "2.4.2", "Source": "Repository", - "Repository": "CRAN", - "Hash": "227045be9aee47e6dda9bb38ac870d67", - "Requirements": [] + "Repository": "RSPM", + "Hash": "227045be9aee47e6dda9bb38ac870d67" }, "rex": { "Package": "rex", "Version": "1.2.1", "Source": "Repository", "Repository": "RSPM", - "Hash": "ae34cd56890607370665bee5bd17812f", - "Requirements": [ - "lazyeval" - ] + "Hash": "ae34cd56890607370665bee5bd17812f" }, "rlang": { "Package": "rlang", - "Version": "1.0.2", + "Version": "1.0.3", "Source": "Repository", - "Repository": "RSPM", - "Hash": "04884d9a75d778aca22c7154b8333ec9", - "Requirements": [] + "Repository": "CRAN", + "Hash": "9103a8f74b2114a5ed1136b471d8feca" }, "roxygen2": { "Package": "roxygen2", "Version": "7.2.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "b390c1d54fcd977cda48588e6172daba", - "Requirements": [ - "R6", - "brew", - "cli", - "commonmark", - "cpp11", - "desc", - "digest", - "knitr", - "pkgload", - "purrr", - "rlang", - "stringi", - "stringr", - "withr", - "xml2" - ] + "Hash": "b390c1d54fcd977cda48588e6172daba" }, "rprojroot": { "Package": "rprojroot", "Version": "2.0.3", "Source": "Repository", - "Repository": "RSPM", - "Hash": "1de7ab598047a87bba48434ba35d497d", - "Requirements": [] - }, - "rstudioapi": { - "Package": "rstudioapi", - "Version": "0.13", - "Source": "Repository", "Repository": "CRAN", - "Hash": "06c85365a03fdaf699966cc1d3cf53ea", - "Requirements": [] + "Hash": "1de7ab598047a87bba48434ba35d497d" }, "spelling": { "Package": "spelling", "Version": "2.2", "Source": "Repository", "Repository": "RSPM", - "Hash": "b8c899a5c83f0d897286550481c91798", - "Requirements": [ - "commonmark", - "hunspell", - "knitr", - "xml2" - ] + "Hash": "b8c899a5c83f0d897286550481c91798" }, "stringi": { "Package": "stringi", "Version": "1.7.6", "Source": "Repository", - "Repository": "CRAN", - "Hash": "bba431031d30789535745a9627ac9271", - "Requirements": [] + "Repository": "RSPM", + "Hash": "bba431031d30789535745a9627ac9271" }, "stringr": { "Package": "stringr", "Version": "1.4.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "0759e6b6c0957edb1311028a49a35e76", - "Requirements": [ - "glue", - "magrittr", - "stringi" - ] + "Repository": "RSPM", + "Hash": "0759e6b6c0957edb1311028a49a35e76" }, "styler": { "Package": "styler", @@ -517,97 +353,65 @@ "RemoteUsername": "r-lib", "RemoteRepo": "styler", "RemoteRef": "HEAD", - "RemoteSha": "459a03f8221b647b37f8ebd3b848058ce37c647f", + "RemoteSha": "9b0faa23decf761fed281844a0956f805feb4054", "RemoteHost": "api.github.com", - "Hash": "f6fdd7fe24cd5e4e1471de6835ee2155", - "Requirements": [ - "R.cache", - "cli", - "magrittr", - "purrr", - "rematch2", - "rlang", - "rprojroot", - "tibble", - "withr" - ] + "Hash": "36c20a96e60d37c2958ef50fcbc6b420" }, "tibble": { "Package": "tibble", "Version": "3.1.7", "Source": "Repository", - "Repository": "CRAN", - "Hash": "08415af406e3dd75049afef9552e7355", - "Requirements": [ - "ellipsis", - "fansi", - "lifecycle", - "magrittr", - "pillar", - "pkgconfig", - "rlang", - "vctrs" - ] + "Repository": "RSPM", + "Hash": "08415af406e3dd75049afef9552e7355" }, "utf8": { "Package": "utf8", "Version": "1.2.2", "Source": "Repository", - "Repository": "CRAN", - "Hash": "c9c462b759a5cc844ae25b5942654d13", - "Requirements": [] + "Repository": "RSPM", + "Hash": "c9c462b759a5cc844ae25b5942654d13" }, "vctrs": { "Package": "vctrs", "Version": "0.4.1", "Source": "Repository", "Repository": "RSPM", - "Hash": "8b54f22e2a58c4f275479c92ce041a57", - "Requirements": [ - "cli", - "glue", - "rlang" - ] + "Hash": "8b54f22e2a58c4f275479c92ce041a57" }, "withr": { "Package": "withr", "Version": "2.5.0", "Source": "Repository", "Repository": "RSPM", - "Hash": "c0e49a9760983e81e55cdd9be92e7182", - "Requirements": [] + "Hash": "c0e49a9760983e81e55cdd9be92e7182" }, "xfun": { "Package": "xfun", "Version": "0.31", "Source": "Repository", "Repository": "RSPM", - "Hash": "a318c6f752b8dcfe9fb74d897418ab2b", - "Requirements": [] + "Hash": "a318c6f752b8dcfe9fb74d897418ab2b" }, "xml2": { "Package": "xml2", "Version": "1.3.3", "Source": "Repository", - "Repository": "CRAN", - "Hash": "40682ed6a969ea5abfd351eb67833adc", - "Requirements": [] + "Repository": "RSPM", + "Hash": "40682ed6a969ea5abfd351eb67833adc" }, "xmlparsedata": { "Package": "xmlparsedata", "Version": "1.0.5", "Source": "Repository", "Repository": "RSPM", - "Hash": "45e4bf3c46476896e821fc0a408fb4fc", - "Requirements": [] + "Hash": "45e4bf3c46476896e821fc0a408fb4fc" }, "yaml": { "Package": "yaml", "Version": "2.3.5", "Source": "Repository", - "Repository": "RSPM", - "Hash": "458bb38374d73bf83b1bb85e353da200", - "Requirements": [] + "Repository": "CRAN", + "Hash": "458bb38374d73bf83b1bb85e353da200" } } } diff --git a/renv/activate.R b/renv/activate.R index f958df789..4a74f3be0 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -7,45 +7,13 @@ local({ # the project directory project <- getwd() - # figure out whether the autoloader is enabled - enabled <- local({ - - # first, check config option - override <- getOption("renv.config.autoloader.enabled") - if (!is.null(override)) - return(override) - - # next, check environment variables - # TODO: prefer using the configuration one in the future - envvars <- c( - "RENV_CONFIG_AUTOLOADER_ENABLED", - "RENV_AUTOLOADER_ENABLED", - "RENV_ACTIVATE_PROJECT" - ) - - for (envvar in envvars) { - envval <- Sys.getenv(envvar, unset = NA) - if (!is.na(envval)) - return(tolower(envval) %in% c("true", "t", "1")) - } - - # enable by default - TRUE - - }) - - if (!enabled) - return(FALSE) - # avoid recursion - if (identical(getOption("renv.autoloader.running"), TRUE)) { - warning("ignoring recursive attempt to run renv autoloader") + if (!is.na(Sys.getenv("RENV_R_INITIALIZING", unset = NA))) return(invisible(TRUE)) - } # signal that we're loading renv during R startup - options(renv.autoloader.running = TRUE) - on.exit(options(renv.autoloader.running = NULL), add = TRUE) + Sys.setenv("RENV_R_INITIALIZING" = "true") + on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE) # signal that we've consented to use renv options(renv.consent = TRUE) @@ -54,15 +22,21 @@ local({ # mask 'utils' packages, will come first on the search path library(utils, lib.loc = .Library) - # unload renv if it's already been loaded - if ("renv" %in% loadedNamespaces()) + # check to see if renv has already been loaded + if ("renv" %in% loadedNamespaces()) { + + # if renv has already been loaded, and it's the requested version of renv, + # nothing to do + spec <- .getNamespaceInfo(.getNamespace("renv"), "spec") + if (identical(spec[["version"]], version)) + return(invisible(TRUE)) + + # otherwise, unload and attempt to load the correct version of renv unloadNamespace("renv") - # load bootstrap tools - `%||%` <- function(x, y) { - if (is.environment(x) || length(x)) x else y } - + + # load bootstrap tools bootstrap <- function(version, library) { # attempt to download renv @@ -88,11 +62,6 @@ local({ if (!is.na(repos)) return(repos) - # check for lockfile repositories - repos <- tryCatch(renv_bootstrap_repos_lockfile(), error = identity) - if (!inherits(repos, "error") && length(repos)) - return(repos) - # if we're testing, re-use the test repositories if (renv_bootstrap_tests_running()) return(getOption("renv.tests.repos")) @@ -101,13 +70,10 @@ local({ repos <- getOption("repos") # ensure @CRAN@ entries are resolved - repos[repos == "@CRAN@"] <- getOption( - "renv.repos.cran", - "https://cloud.r-project.org" - ) + repos[repos == "@CRAN@"] <- "https://cloud.r-project.org" # add in renv.bootstrap.repos if set - default <- c(FALLBACK = "https://cloud.r-project.org") + default <- c(CRAN = "https://cloud.r-project.org") extra <- getOption("renv.bootstrap.repos", default = default) repos <- c(repos, extra) @@ -117,30 +83,6 @@ local({ } - renv_bootstrap_repos_lockfile <- function() { - - lockpath <- Sys.getenv("RENV_PATHS_LOCKFILE", unset = "renv.lock") - if (!file.exists(lockpath)) - return(NULL) - - lockfile <- tryCatch(renv_json_read(lockpath), error = identity) - if (inherits(lockfile, "error")) { - warning(lockfile) - return(NULL) - } - - repos <- lockfile$R$Repositories - if (length(repos) == 0) - return(NULL) - - keys <- vapply(repos, `[[`, "Name", FUN.VALUE = character(1)) - vals <- vapply(repos, `[[`, "URL", FUN.VALUE = character(1)) - names(vals) <- keys - - return(vals) - - } - renv_bootstrap_download <- function(version) { # if the renv version number has 4 components, assume it must @@ -148,20 +90,16 @@ local({ nv <- numeric_version(version) components <- unclass(nv)[[1]] - # if this appears to be a development version of 'renv', we'll - # try to restore from github - dev <- length(components) == 4L - - # begin collecting different methods for finding renv - methods <- c( - renv_bootstrap_download_tarball, - if (dev) + methods <- if (length(components) == 4L) { + list( renv_bootstrap_download_github - else c( + ) + } else { + list( renv_bootstrap_download_cran_latest, renv_bootstrap_download_cran_archive ) - ) + } for (method in methods) { path <- tryCatch(method(version), error = identity) @@ -196,20 +134,16 @@ local({ renv_bootstrap_download_cran_latest <- function(version) { - spec <- renv_bootstrap_download_cran_latest_find(version) - - message("* Downloading renv ", version, " ... ", appendLF = FALSE) + repos <- renv_bootstrap_download_cran_latest_find(version) - type <- spec$type - repos <- spec$repos + message("* Downloading renv ", version, " from CRAN ... ", appendLF = FALSE) info <- tryCatch( utils::download.packages( - pkgs = "renv", + pkgs = "renv", + repos = repos, destdir = tempdir(), - repos = repos, - type = type, - quiet = TRUE + quiet = TRUE ), condition = identity ) @@ -219,52 +153,36 @@ local({ return(FALSE) } - # report success and return - message("OK (downloaded ", type, ")") + message("OK") info[1, 2] } renv_bootstrap_download_cran_latest_find <- function(version) { - # check whether binaries are supported on this system - binary <- - getOption("renv.bootstrap.binary", default = TRUE) && - !identical(.Platform$pkgType, "source") && - !identical(getOption("pkgType"), "source") && - Sys.info()[["sysname"]] %in% c("Darwin", "Windows") - - types <- c(if (binary) "binary", "source") + all <- renv_bootstrap_repos() - # iterate over types + repositories - for (type in types) { - for (repos in renv_bootstrap_repos()) { + for (repos in all) { - # retrieve package database - db <- tryCatch( - as.data.frame( - utils::available.packages(type = type, repos = repos), - stringsAsFactors = FALSE - ), - error = identity - ) + db <- tryCatch( + as.data.frame( + x = utils::available.packages(repos = repos), + stringsAsFactors = FALSE + ), + error = identity + ) - if (inherits(db, "error")) - next + if (inherits(db, "error")) + next - # check for compatible entry - entry <- db[db$Package %in% "renv" & db$Version %in% version, ] - if (nrow(entry) == 0) - next + entry <- db[db$Package %in% "renv" & db$Version %in% version, ] + if (nrow(entry) == 0) + next - # found it; return spec to caller - spec <- list(entry = entry, type = type, repos = repos) - return(spec) + return(repos) - } } - # if we got here, we failed to find renv fmt <- "renv %s is not available from your declared package repositories" stop(sprintf(fmt, version)) @@ -277,7 +195,7 @@ local({ urls <- file.path(repos, "src/contrib/Archive/renv", name) destfile <- file.path(tempdir(), name) - message("* Downloading renv ", version, " ... ", appendLF = FALSE) + message("* Downloading renv ", version, " from CRAN archive ... ", appendLF = FALSE) for (url in urls) { @@ -298,42 +216,6 @@ local({ } - renv_bootstrap_download_tarball <- function(version) { - - # if the user has provided the path to a tarball via - # an environment variable, then use it - tarball <- Sys.getenv("RENV_BOOTSTRAP_TARBALL", unset = NA) - if (is.na(tarball)) - return() - - # allow directories - info <- file.info(tarball, extra_cols = FALSE) - if (identical(info$isdir, TRUE)) { - name <- sprintf("renv_%s.tar.gz", version) - tarball <- file.path(tarball, name) - } - - # bail if it doesn't exist - if (!file.exists(tarball)) { - - # let the user know we weren't able to honour their request - fmt <- "* RENV_BOOTSTRAP_TARBALL is set (%s) but does not exist." - msg <- sprintf(fmt, tarball) - warning(msg) - - # bail - return() - - } - - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) - - tarball - - } - renv_bootstrap_download_github <- function(version) { enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE") @@ -387,13 +269,7 @@ local({ bin <- R.home("bin") exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" r <- file.path(bin, exe) - - args <- c( - "--vanilla", "CMD", "INSTALL", "--no-multiarch", - "-l", shQuote(path.expand(library)), - shQuote(path.expand(tarball)) - ) - + args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(library), shQuote(tarball)) output <- system2(r, args, stdout = TRUE, stderr = TRUE) message("Done!") @@ -410,7 +286,7 @@ local({ } - renv_bootstrap_platform_prefix <- function() { + renv_bootstrap_prefix <- function() { # construct version prefix version <- paste(R.version$major, R.version$minor, sep = ".") @@ -429,8 +305,8 @@ local({ components <- c(prefix, R.version$platform) # include prefix if provided by user - prefix <- renv_bootstrap_platform_prefix_impl() - if (!is.na(prefix) && nzchar(prefix)) + prefix <- Sys.getenv("RENV_PATHS_PREFIX") + if (nzchar(prefix)) components <- c(prefix, components) # build prefix @@ -438,139 +314,6 @@ local({ } - renv_bootstrap_platform_prefix_impl <- function() { - - # if an explicit prefix has been supplied, use it - prefix <- Sys.getenv("RENV_PATHS_PREFIX", unset = NA) - if (!is.na(prefix)) - return(prefix) - - # if the user has requested an automatic prefix, generate it - auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) - if (auto %in% c("TRUE", "True", "true", "1")) - return(renv_bootstrap_platform_prefix_auto()) - - # empty string on failure - "" - - } - - renv_bootstrap_platform_prefix_auto <- function() { - - prefix <- tryCatch(renv_bootstrap_platform_os(), error = identity) - if (inherits(prefix, "error") || prefix %in% "unknown") { - - msg <- paste( - "failed to infer current operating system", - "please file a bug report at https://github.com/rstudio/renv/issues", - sep = "; " - ) - - warning(msg) - - } - - prefix - - } - - renv_bootstrap_platform_os <- function() { - - sysinfo <- Sys.info() - sysname <- sysinfo[["sysname"]] - - # handle Windows + macOS up front - if (sysname == "Windows") - return("windows") - else if (sysname == "Darwin") - return("macos") - - # check for os-release files - for (file in c("/etc/os-release", "/usr/lib/os-release")) - if (file.exists(file)) - return(renv_bootstrap_platform_os_via_os_release(file, sysinfo)) - - # check for redhat-release files - if (file.exists("/etc/redhat-release")) - return(renv_bootstrap_platform_os_via_redhat_release()) - - "unknown" - - } - - renv_bootstrap_platform_os_via_os_release <- function(file, sysinfo) { - - # read /etc/os-release - release <- utils::read.table( - file = file, - sep = "=", - quote = c("\"", "'"), - col.names = c("Key", "Value"), - comment.char = "#", - stringsAsFactors = FALSE - ) - - vars <- as.list(release$Value) - names(vars) <- release$Key - - # get os name - os <- tolower(sysinfo[["sysname"]]) - - # read id - id <- "unknown" - for (field in c("ID", "ID_LIKE")) { - if (field %in% names(vars) && nzchar(vars[[field]])) { - id <- vars[[field]] - break - } - } - - # read version - version <- "unknown" - for (field in c("UBUNTU_CODENAME", "VERSION_CODENAME", "VERSION_ID", "BUILD_ID")) { - if (field %in% names(vars) && nzchar(vars[[field]])) { - version <- vars[[field]] - break - } - } - - # join together - paste(c(os, id, version), collapse = "-") - - } - - renv_bootstrap_platform_os_via_redhat_release <- function() { - - # read /etc/redhat-release - contents <- readLines("/etc/redhat-release", warn = FALSE) - - # infer id - id <- if (grepl("centos", contents, ignore.case = TRUE)) - "centos" - else if (grepl("redhat", contents, ignore.case = TRUE)) - "redhat" - else - "unknown" - - # try to find a version component (very hacky) - version <- "unknown" - - parts <- strsplit(contents, "[[:space:]]")[[1L]] - for (part in parts) { - - nv <- tryCatch(numeric_version(part), error = identity) - if (inherits(nv, "error")) - next - - version <- nv[1, 1] - break - - } - - paste(c("linux", id, version), collapse = "-") - - } - renv_bootstrap_library_root_name <- function(project) { # use project name as-is if requested @@ -586,33 +329,17 @@ local({ renv_bootstrap_library_root <- function(project) { - prefix <- renv_bootstrap_profile_prefix() - path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA) if (!is.na(path)) - return(paste(c(path, prefix), collapse = "/")) + return(path) - path <- renv_bootstrap_library_root_impl(project) - if (!is.null(path)) { + path <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) + if (!is.na(path)) { name <- renv_bootstrap_library_root_name(project) - return(paste(c(path, prefix, name), collapse = "/")) + return(file.path(path, name)) } - renv_bootstrap_paths_renv("library", project = project) - - } - - renv_bootstrap_library_root_impl <- function(project) { - - root <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) - if (!is.na(root)) - return(root) - - type <- renv_bootstrap_project_type(project) - if (identical(type, "package")) { - userdir <- renv_bootstrap_user_dir() - return(file.path(userdir, "library")) - } + file.path(project, "renv/library") } @@ -669,241 +396,12 @@ local({ TRUE } - - renv_bootstrap_profile_load <- function(project) { - - # if RENV_PROFILE is already set, just use that - profile <- Sys.getenv("RENV_PROFILE", unset = NA) - if (!is.na(profile) && nzchar(profile)) - return(profile) - - # check for a profile file (nothing to do if it doesn't exist) - path <- renv_bootstrap_paths_renv("profile", profile = FALSE) - if (!file.exists(path)) - return(NULL) - - # read the profile, and set it if it exists - contents <- readLines(path, warn = FALSE) - if (length(contents) == 0L) - return(NULL) - - # set RENV_PROFILE - profile <- contents[[1L]] - if (!profile %in% c("", "default")) - Sys.setenv(RENV_PROFILE = profile) - - profile - - } - - renv_bootstrap_profile_prefix <- function() { - profile <- renv_bootstrap_profile_get() - if (!is.null(profile)) - return(file.path("profiles", profile, "renv")) - } - - renv_bootstrap_profile_get <- function() { - profile <- Sys.getenv("RENV_PROFILE", unset = "") - renv_bootstrap_profile_normalize(profile) - } - - renv_bootstrap_profile_set <- function(profile) { - profile <- renv_bootstrap_profile_normalize(profile) - if (is.null(profile)) - Sys.unsetenv("RENV_PROFILE") - else - Sys.setenv(RENV_PROFILE = profile) - } - - renv_bootstrap_profile_normalize <- function(profile) { - - if (is.null(profile) || profile %in% c("", "default")) - return(NULL) - - profile - - } - - renv_bootstrap_path_absolute <- function(path) { - - substr(path, 1L, 1L) %in% c("~", "/", "\\") || ( - substr(path, 1L, 1L) %in% c(letters, LETTERS) && - substr(path, 2L, 3L) %in% c(":/", ":\\") - ) - - } - - renv_bootstrap_paths_renv <- function(..., profile = TRUE, project = NULL) { - renv <- Sys.getenv("RENV_PATHS_RENV", unset = "renv") - root <- if (renv_bootstrap_path_absolute(renv)) NULL else project - prefix <- if (profile) renv_bootstrap_profile_prefix() - components <- c(root, renv, prefix, ...) - paste(components, collapse = "/") - } - - renv_bootstrap_project_type <- function(path) { - - descpath <- file.path(path, "DESCRIPTION") - if (!file.exists(descpath)) - return("unknown") - - desc <- tryCatch( - read.dcf(descpath, all = TRUE), - error = identity - ) - - if (inherits(desc, "error")) - return("unknown") - - type <- desc$Type - if (!is.null(type)) - return(tolower(type)) - - package <- desc$Package - if (!is.null(package)) - return("package") - - "unknown" - - } - - renv_bootstrap_user_dir <- function() { - dir <- renv_bootstrap_user_dir_impl() - path.expand(chartr("\\", "/", dir)) - } - - renv_bootstrap_user_dir_impl <- function() { - - # use local override if set - override <- getOption("renv.userdir.override") - if (!is.null(override)) - return(override) - - # use R_user_dir if available - tools <- asNamespace("tools") - if (is.function(tools$R_user_dir)) - return(tools$R_user_dir("renv", "cache")) - - # try using our own backfill for older versions of R - envvars <- c("R_USER_CACHE_DIR", "XDG_CACHE_HOME") - for (envvar in envvars) { - root <- Sys.getenv(envvar, unset = NA) - if (!is.na(root)) - return(file.path(root, "R/renv")) - } - - # use platform-specific default fallbacks - if (Sys.info()[["sysname"]] == "Windows") - file.path(Sys.getenv("LOCALAPPDATA"), "R/cache/R/renv") - else if (Sys.info()[["sysname"]] == "Darwin") - "~/Library/Caches/org.R-project.R/R/renv" - else - "~/.cache/R/renv" - - } - - - renv_json_read <- function(file = NULL, text = NULL) { - - text <- paste(text %||% read(file), collapse = "\n") - - # find strings in the JSON - pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' - locs <- gregexpr(pattern, text, perl = TRUE)[[1]] - - # if any are found, replace them with placeholders - replaced <- text - strings <- character() - replacements <- character() - - if (!identical(c(locs), -1L)) { - - # get the string values - starts <- locs - ends <- locs + attr(locs, "match.length") - 1L - strings <- substring(text, starts, ends) - - # only keep those requiring escaping - strings <- grep("[[\\]{}:]", strings, perl = TRUE, value = TRUE) - - # compute replacements - replacements <- sprintf('"\032%i\032"', seq_along(strings)) - - # replace the strings - mapply(function(string, replacement) { - replaced <<- sub(string, replacement, replaced, fixed = TRUE) - }, strings, replacements) - - } - - # transform the JSON into something the R parser understands - transformed <- replaced - transformed <- gsub("[[{]", "list(", transformed) - transformed <- gsub("[]}]", ")", transformed) - transformed <- gsub(":", "=", transformed, fixed = TRUE) - text <- paste(transformed, collapse = "\n") - - # parse it - json <- parse(text = text, keep.source = FALSE, srcfile = NULL)[[1L]] - - # construct map between source strings, replaced strings - map <- as.character(parse(text = strings)) - names(map) <- as.character(parse(text = replacements)) - - # convert to list - map <- as.list(map) - - # remap strings in object - remapped <- renv_json_remap(json, map) - - # evaluate - eval(remapped, envir = baseenv()) - - } - - renv_json_remap <- function(json, map) { - - # fix names - if (!is.null(names(json))) { - lhs <- match(names(json), names(map), nomatch = 0L) - rhs <- match(names(map), names(json), nomatch = 0L) - names(json)[rhs] <- map[lhs] - } - - # fix values - if (is.character(json)) - return(map[[json]] %||% json) - - # handle true, false, null - if (is.name(json)) { - text <- as.character(json) - if (text == "true") - return(TRUE) - else if (text == "false") - return(FALSE) - else if (text == "null") - return(NULL) - } - - # recurse - if (is.recursive(json)) { - for (i in seq_along(json)) { - json[i] <- list(renv_json_remap(json[[i]], map)) - } - } - - json - - } - - # load the renv profile, if any - renv_bootstrap_profile_load(project) # construct path to library root root <- renv_bootstrap_library_root(project) # construct library prefix for platform - prefix <- renv_bootstrap_platform_prefix() + prefix <- renv_bootstrap_prefix() # construct full libpath libpath <- file.path(root, prefix) diff --git a/tests/testthat/test-hook-roxygenize.R b/tests/testthat/test-hook-roxygenize.R index 37cdce2ef..e9f743634 100644 --- a/tests/testthat/test-hook-roxygenize.R +++ b/tests/testthat/test-hook-roxygenize.R @@ -83,7 +83,7 @@ test_that("asserting installed dependencies", { writeLines(generate_uninstalled_pkg_call(), "R/core.R") testthat::expect_error( roxygen_assert_additional_dependencies(), - "requires all dependencies of your package" + "there is no package called" ) }) @@ -125,7 +125,7 @@ test_that("fails gratefully when not installed package is called (packageNotFoun # when there is a missing package expect_error( roxygenize_with_cache(list(getwd()), dirs = dirs_R.cache("roxygenize")), - "Please add the package as a dependency" + "there is no package called" ) }) @@ -139,7 +139,7 @@ test_that("fails gratefully when not installed package is required according to suppressWarnings( roxygenize_with_cache(list(getwd()), dirs = dirs_R.cache("roxygenize")) ), - "Please add the package" + "The package .* is required" ) })