From 38677ac7c67eb242d081d3948e1808c63086cdbd Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 21:08:20 +0200 Subject: [PATCH 1/7] mention bdc 1.5 in cran comments --- cran-comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cran-comments.md b/cran-comments.md index 990d723..e30c8ea 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,7 +1,7 @@ ## R CMD check results * Namespace in Imports field not imported from: ‘doParallel’ -* * Some package seems to depend on it without declaring it; tests fail without having it installed +* * bdc 1.1.4 depends on it without declaring it; tests fail without having it installed - fix will come with 1.1.5 * Regarding `no visible binding for global varible X` for column names: * * Should we really just define a local variable with the same name to silence the linter? That seems odd. From 406739b5750fa5184674c697d46469b43ddc2144 Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 21:31:29 +0200 Subject: [PATCH 2/7] upgrade to renv 1.0.0 --- renv.lock | 9 +- renv/activate.R | 375 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 264 insertions(+), 120 deletions(-) diff --git a/renv.lock b/renv.lock index 632a0c7..9e2b553 100644 --- a/renv.lock +++ b/renv.lock @@ -1295,13 +1295,8 @@ }, "renv": { "Package": "renv", - "Version": "0.17.3", - "Source": "Repository", - "Repository": "CRAN", - "Requirements": [ - "utils" - ], - "Hash": "4543b8cd233ae25c6aba8548be9e747e" + "Version": "1.0.0", + "Source": "Repository" }, "rgbif": { "Package": "rgbif", diff --git a/renv/activate.R b/renv/activate.R index a8fdc32..cc742fc 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,7 +2,8 @@ local({ # the requested version of renv - version <- "0.17.3" + version <- "1.0.0" + attr(version, "sha") <- NULL # the project directory project <- getwd() @@ -60,25 +61,75 @@ local({ # load bootstrap tools `%||%` <- function(x, y) { - if (is.environment(x) || length(x)) x else y + if (is.null(x)) y else x } - `%??%` <- function(x, y) { - if (is.null(x)) y else x + catf <- function(fmt, ..., appendLF = TRUE) { + + quiet <- getOption("renv.bootstrap.quiet", default = FALSE) + if (quiet) + return(invisible()) + + msg <- sprintf(fmt, ...) + cat(msg, file = stdout(), sep = if (appendLF) "\n" else "") + + invisible(msg) + + } + + header <- function(label, + ..., + prefix = "#", + suffix = "-", + n = min(getOption("width"), 78)) + { + label <- sprintf(label, ...) + n <- max(n - nchar(label) - nchar(prefix) - 2L, 8L) + if (n <= 0) + return(paste(prefix, label)) + + tail <- paste(rep.int(suffix, n), collapse = "") + paste0(prefix, " ", label, " ", tail) + + } + + startswith <- function(string, prefix) { + substring(string, 1, nchar(prefix)) == prefix } bootstrap <- function(version, library) { + friendly <- renv_bootstrap_version_friendly(version) + section <- header(sprintf("Bootstrapping renv %s", friendly)) + catf(section) + # attempt to download renv - tarball <- tryCatch(renv_bootstrap_download(version), error = identity) - if (inherits(tarball, "error")) - stop("failed to download renv ", version) + catf("- Downloading renv ... ", appendLF = FALSE) + withCallingHandlers( + tarball <- renv_bootstrap_download(version), + error = function(err) { + catf("FAILED") + stop("failed to download:\n", conditionMessage(err)) + } + ) + catf("OK") + on.exit(unlink(tarball), add = TRUE) # now attempt to install - status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity) - if (inherits(status, "error")) - stop("failed to install renv ", version) + catf("- Installing renv ... ", appendLF = FALSE) + withCallingHandlers( + status <- renv_bootstrap_install(version, tarball, library), + error = function(err) { + catf("FAILED") + stop("failed to install:\n", conditionMessage(err)) + } + ) + catf("OK") + + # add empty line to break up bootstrapping from normal output + catf("") + return(invisible()) } renv_bootstrap_tests_running <- function() { @@ -108,13 +159,6 @@ local({ if (!inherits(repos, "error") && length(repos)) return(repos) - # if we're testing, re-use the test repositories - if (renv_bootstrap_tests_running()) { - repos <- getOption("renv.tests.repos") - if (!is.null(repos)) - return(repos) - } - # retrieve current repos repos <- getOption("repos") @@ -158,33 +202,34 @@ local({ renv_bootstrap_download <- function(version) { - # if the renv version number has 4 components, assume it must - # be retrieved via github - 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) - renv_bootstrap_download_github - else c( - renv_bootstrap_download_cran_latest, - renv_bootstrap_download_cran_archive + sha <- attr(version, "sha", exact = TRUE) + + methods <- if (!is.null(sha)) { + + # attempting to bootstrap a development version of renv + c( + function() renv_bootstrap_download_tarball(sha), + function() renv_bootstrap_download_github(sha) ) - ) + + } else { + + # attempting to bootstrap a release version of renv + c( + function() renv_bootstrap_download_tarball(version), + function() renv_bootstrap_download_cran_latest(version), + function() renv_bootstrap_download_cran_archive(version) + ) + + } for (method in methods) { - path <- tryCatch(method(version), error = identity) + path <- tryCatch(method(), error = identity) if (is.character(path) && file.exists(path)) return(path) } - stop("failed to download renv ", version) + stop("All download methods failed") } @@ -248,8 +293,6 @@ local({ type <- spec$type repos <- spec$repos - message("* Downloading renv ", version, " ... ", appendLF = FALSE) - baseurl <- utils::contrib.url(repos = repos, type = type) ext <- if (identical(type, "source")) ".tar.gz" @@ -266,13 +309,10 @@ local({ condition = identity ) - if (inherits(status, "condition")) { - message("FAILED") + if (inherits(status, "condition")) return(FALSE) - } # report success and return - message("OK (downloaded ", type, ")") destfile } @@ -329,8 +369,6 @@ local({ urls <- file.path(repos, "src/contrib/Archive/renv", name) destfile <- file.path(tempdir(), name) - message("* Downloading renv ", version, " ... ", appendLF = FALSE) - for (url in urls) { status <- tryCatch( @@ -338,14 +376,11 @@ local({ condition = identity ) - if (identical(status, 0L)) { - message("OK") + if (identical(status, 0L)) return(destfile) - } } - message("FAILED") return(FALSE) } @@ -368,7 +403,7 @@ local({ 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." + fmt <- "- RENV_BOOTSTRAP_TARBALL is set (%s) but does not exist." msg <- sprintf(fmt, tarball) warning(msg) @@ -377,10 +412,7 @@ local({ } - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) - + catf("- Using local tarball '%s'.", tarball) tarball } @@ -407,8 +439,6 @@ local({ on.exit(do.call(base::options, saved), add = TRUE) } - message("* Downloading renv ", version, " from GitHub ... ", appendLF = FALSE) - url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version) name <- sprintf("renv_%s.tar.gz", version) destfile <- file.path(tempdir(), name) @@ -418,26 +448,105 @@ local({ condition = identity ) - if (!identical(status, 0L)) { - message("FAILED") + if (!identical(status, 0L)) return(FALSE) - } - message("OK") + renv_bootstrap_download_augment(destfile) + return(destfile) } + # Add Sha to DESCRIPTION. This is stop gap until #890, after which we + # can use renv::install() to fully capture metadata. + renv_bootstrap_download_augment <- function(destfile) { + sha <- renv_bootstrap_git_extract_sha1_tar(destfile) + if (is.null(sha)) { + return() + } + + # Untar + tempdir <- tempfile("renv-github-") + on.exit(unlink(tempdir, recursive = TRUE), add = TRUE) + untar(destfile, exdir = tempdir) + pkgdir <- dir(tempdir, full.names = TRUE)[[1]] + + # Modify description + desc_path <- file.path(pkgdir, "DESCRIPTION") + desc_lines <- readLines(desc_path) + remotes_fields <- c( + "RemoteType: github", + "RemoteHost: api.github.com", + "RemoteRepo: renv", + "RemoteUsername: rstudio", + "RemotePkgRef: rstudio/renv", + paste("RemoteRef: ", sha), + paste("RemoteSha: ", sha) + ) + writeLines(c(desc_lines[desc_lines != ""], remotes_fields), con = desc_path) + + # Re-tar + local({ + old <- setwd(tempdir) + on.exit(setwd(old), add = TRUE) + + tar(destfile, compression = "gzip") + }) + invisible() + } + + # Extract the commit hash from a git archive. Git archives include the SHA1 + # hash as the comment field of the tarball pax extended header + # (see https://www.kernel.org/pub/software/scm/git/docs/git-archive.html) + # For GitHub archives this should be the first header after the default one + # (512 byte) header. + renv_bootstrap_git_extract_sha1_tar <- function(bundle) { + + # open the bundle for reading + # We use gzcon for everything because (from ?gzcon) + # > Reading from a connection which does not supply a ‘gzip’ magic + # > header is equivalent to reading from the original connection + conn <- gzcon(file(bundle, open = "rb", raw = TRUE)) + on.exit(close(conn)) + + # The default pax header is 512 bytes long and the first pax extended header + # with the comment should be 51 bytes long + # `52 comment=` (11 chars) + 40 byte SHA1 hash + len <- 0x200 + 0x33 + res <- rawToChar(readBin(conn, "raw", n = len)[0x201:len]) + + if (grepl("^52 comment=", res)) { + sub("52 comment=", "", res) + } else { + NULL + } + } + renv_bootstrap_install <- function(version, tarball, library) { # attempt to install it into project library - message("* Installing renv ", version, " ... ", appendLF = FALSE) dir.create(library, showWarnings = FALSE, recursive = TRUE) + output <- renv_bootstrap_install_impl(library, tarball) + + # check for successful install + status <- attr(output, "status") + if (is.null(status) || identical(status, 0L)) + return(status) + + # an error occurred; report it + header <- "installation of renv failed" + lines <- paste(rep.int("=", nchar(header)), collapse = "") + text <- paste(c(header, lines, output), collapse = "\n") + stop(text) + + } + + renv_bootstrap_install_impl <- function(library, tarball) { # invoke using system2 so we can capture and report output bin <- R.home("bin") exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" - r <- file.path(bin, exe) + R <- file.path(bin, exe) args <- c( "--vanilla", "CMD", "INSTALL", "--no-multiarch", @@ -445,19 +554,7 @@ local({ shQuote(path.expand(tarball)) ) - output <- system2(r, args, stdout = TRUE, stderr = TRUE) - message("Done!") - - # check for successful install - status <- attr(output, "status") - if (is.numeric(status) && !identical(status, 0L)) { - header <- "Error installing renv:" - lines <- paste(rep.int("=", nchar(header)), collapse = "") - text <- c(header, lines, output) - writeLines(text, con = stderr()) - } - - status + system2(R, args, stdout = TRUE, stderr = TRUE) } @@ -667,34 +764,60 @@ local({ } - renv_bootstrap_validate_version <- function(version) { + renv_bootstrap_validate_version <- function(version, description = NULL) { - loadedversion <- utils::packageDescription("renv", fields = "Version") - if (version == loadedversion) - return(TRUE) + # resolve description file + description <- description %||% { + path <- getNamespaceInfo("renv", "path") + packageDescription("renv", lib.loc = dirname(path)) + } - # assume four-component versions are from GitHub; - # three-component versions are from CRAN - components <- strsplit(loadedversion, "[.-]")[[1]] - remote <- if (length(components) == 4L) - paste("rstudio/renv", loadedversion, sep = "@") + # check whether requested version 'version' matches loaded version of renv + sha <- attr(version, "sha", exact = TRUE) + valid <- if (!is.null(sha)) + renv_bootstrap_validate_version_dev(sha, description) else - paste("renv", loadedversion, sep = "@") + renv_bootstrap_validate_version_release(version, description) + + if (valid) + return(TRUE) + + # the loaded version of renv doesn't match the requested version; + # give the user instructions on how to proceed + remote <- if (!is.null(description[["RemoteSha"]])) { + paste("rstudio/renv", description[["RemoteSha"]], sep = "@") + } else { + paste("renv", description[["Version"]], sep = "@") + } + + # display both loaded version + sha if available + friendly <- renv_bootstrap_version_friendly( + version = description[["Version"]], + sha = description[["RemoteSha"]] + ) fmt <- paste( "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.", - "Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", - "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", + "- Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", + "- Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", sep = "\n" ) - - msg <- sprintf(fmt, loadedversion, version, remote) - warning(msg, call. = FALSE) + catf(fmt, friendly, renv_bootstrap_version_friendly(version), remote) FALSE } + renv_bootstrap_validate_version_dev <- function(version, description) { + expected <- description[["RemoteSha"]] + is.character(expected) && startswith(expected, version) + } + + renv_bootstrap_validate_version_release <- function(version, description) { + expected <- description[["Version"]] + is.character(expected) && identical(expected, version) + } + renv_bootstrap_hash_text <- function(text) { hashfile <- tempfile("renv-hash-") @@ -859,6 +982,40 @@ local({ } + renv_bootstrap_version_friendly <- function(version, sha = NULL) { + sha <- sha %||% attr(version, "sha", exact = TRUE) + parts <- c(version, sprintf("[sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = " ") + } + + renv_bootstrap_run <- function(version, libpath) { + + # perform bootstrap + bootstrap(version, libpath) + + # exit early if we're just testing bootstrap + if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) + return(TRUE) + + # try again to load + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + return(renv::load(project = getwd())) + } + + # failed to download or load renv; warn the user + msg <- c( + "Failed to find an renv installation: the project will not be loaded.", + "Use `renv::activate()` to re-initialize the project." + ) + + warning(paste(msg, collapse = "\n"), call. = FALSE) + + } + + + renv_bootstrap_in_rstudio <- function() { + commandArgs()[[1]] == "RStudio" + } renv_json_read <- function(file = NULL, text = NULL) { @@ -1002,31 +1159,23 @@ local({ if (renv_bootstrap_load(project, libpath, version)) return(TRUE) - # load failed; inform user we're about to bootstrap - prefix <- paste("# Bootstrapping renv", version) - postfix <- paste(rep.int("-", 77L - nchar(prefix)), collapse = "") - header <- paste(prefix, postfix) - message(header) + if (renv_bootstrap_in_rstudio()) { + setHook("rstudio.sessionInit", function(...) { + renv_bootstrap_run(version, libpath) - # perform bootstrap - bootstrap(version, libpath) - - # exit early if we're just testing bootstrap - if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) - return(TRUE) - - # try again to load - if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { - message("* Successfully installed and loaded renv ", version, ".") - return(renv::load()) + # Work around buglet in RStudio if hook uses readline + tryCatch( + { + tools <- as.environment("tools:rstudio") + tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE) + }, + error = function(cnd) {} + ) + }) + } else { + renv_bootstrap_run(version, libpath) } - # failed to download or load renv; warn the user - msg <- c( - "Failed to find an renv installation: the project will not be loaded.", - "Use `renv::activate()` to re-initialize the project." - ) - - warning(paste(msg, collapse = "\n"), call. = FALSE) + invisible() }) From c9cc08f8a1d94d183e47850a224725ee74691899 Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 22:28:09 +0200 Subject: [PATCH 3/7] missing renv upgrade steps --- renv.lock | 3 +++ 1 file changed, 3 insertions(+) diff --git a/renv.lock b/renv.lock index 9e2b553..76b8ee2 100644 --- a/renv.lock +++ b/renv.lock @@ -1296,6 +1296,9 @@ "renv": { "Package": "renv", "Version": "1.0.0", + "OS_type": null, + "NeedsCompilation": "no", + "Repository": "CRAN", "Source": "Repository" }, "rgbif": { From 1fe5e173e6d5ca95751e733434f548346622a9bd Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 23:14:37 +0200 Subject: [PATCH 4/7] update man --- man/clean_taxon_names.Rd | 2 +- man/get_habitat_data.Rd | 2 +- man/select_traits_tax_dist.Rd | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/man/clean_taxon_names.Rd b/man/clean_taxon_names.Rd index 62ee895..1801a78 100644 --- a/man/clean_taxon_names.Rd +++ b/man/clean_taxon_names.Rd @@ -39,5 +39,5 @@ This function takes a data.frame with target_taxa and uses the bdc package to clean and harmonise the names. } \author{ -James G. Hagan (james_hagan(at)outlook.com) +James G. Hagan (james_hagan(at)outlook.com) and Ronald Bergmann } diff --git a/man/get_habitat_data.Rd b/man/get_habitat_data.Rd index 4e7a8cd..5ad12b1 100644 --- a/man/get_habitat_data.Rd +++ b/man/get_habitat_data.Rd @@ -36,5 +36,5 @@ and gets data on biogeographic realm, major habitat type and ecoregion based on Abell et al.'s (2008) freshwater ecoregion map. } \author{ -James G. Hagan (james_hagan(at)outlook.com) +James G. Hagan (james_hagan(at)outlook.com) and Ronald Bergmann } diff --git a/man/select_traits_tax_dist.Rd b/man/select_traits_tax_dist.Rd index 19976b2..97e25f3 100644 --- a/man/select_traits_tax_dist.Rd +++ b/man/select_traits_tax_dist.Rd @@ -8,6 +8,7 @@ select_traits_tax_dist( data, target_taxon, body_size, + life_stage, max_tax_dist = 3, trait = "equation", gen_sp_dist = 0.5 @@ -28,6 +29,11 @@ taxon names \item column name containing the body length data }} +\item{life_stage}{\itemize{ +\item character string with the column name containing the +life-stage information +}} + \item{max_tax_dist}{\itemize{ \item maximum taxonomic distance acceptable between the target and the taxa in the database (default = 3) From 6a469080eb04cf826c31b3c58097b9d4125aa791 Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 23:16:23 +0200 Subject: [PATCH 5/7] add required stuff around vignettes via usethis --- .Rbuildignore | 2 +- .devcontainer/Dockerfile | 1 + .gitignore | 1 + DESCRIPTION | 3 +++ NEWS.md | 2 +- vignettes/.gitignore | 2 ++ vignettes/InvTraitR_vignette.Rmd | 23 +++++++++++++++++------ 7 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 vignettes/.gitignore diff --git a/.Rbuildignore b/.Rbuildignore index 8adea00..13959ad 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -11,4 +11,4 @@ .github database companion_scripts -cran-comments.md \ No newline at end of file +cran-comments.md diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a5728c0..af64295 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,6 +7,7 @@ RUN apt update \ libgdal-dev \ libudunits2-dev \ cmake \ + pandoc \ && : # install dev dependencies diff --git a/.gitignore b/.gitignore index 999926f..9236faa 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ vignettes/*.pdf # R Environment Variables .Renviron +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index 60562a1..cf73f63 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,5 +30,8 @@ Imports: rappdirs, doParallel Suggests: + knitr, + rmarkdown, testthat (>= 3.0.0) Config/testthat/edition: 3 +VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 661e12c..5b1d042 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,3 @@ -# InvertR +# InvTraitR (0.0.0.1) * Added a `NEWS.md` file to track changes to the package. diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/InvTraitR_vignette.Rmd b/vignettes/InvTraitR_vignette.Rmd index e5b00cd..65e3924 100644 --- a/vignettes/InvTraitR_vignette.Rmd +++ b/vignettes/InvTraitR_vignette.Rmd @@ -1,10 +1,24 @@ --- title: "Dry biomass of freshwater invertebrates using InvTraitR" -author: "James Hagan" -date: "`r Sys.Date()`" output: rmarkdown::html_vignette +author: "James Hagan" +vignette: > + %\VignetteIndexEntry{Dry biomass of freshwater invertebrates using InvTraitR} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} --- +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(InvTraitR) +``` + To see how we can use *InvTraitR* to obtain estimates of the dry biomass of freshwater invertebrates using taxon names and geographical coordinates, we will start by loading some relevant packages and some test data. The test data consist of a set of 89 invertebrate taxa collected in freshwater rockpools on six rocky outcrops (often called inselbergs) in five countries. In addition, the data consist of latitude-longitude coordinates for the samples as well as measured body lengths for all the taxa (some body lenghts were compiled from the literature) @@ -53,14 +67,13 @@ length(unique(dol_df$country_code_XXX)) # check the summary statistics summary(dol_df) - ``` We want to use the body length data to estimate the dry biomass for each of these samples using length-dry biomass allometric equations. The *InvTraitR* package houses a database of more than 350 length-dry biomass allometric equations that represent most major groups of freshwater invertebrates globally. We can use *InvTraitR* to search this database for appropriate length-dry biomass equations for the samples in our test data (`dol_df`). To do this, we have two options both of which rely on the `get_trait_from_taxon()` function. This function (see below) takes a data.frame with at least five columns. These columns are the taxon name for which dry biomass data are required, the life stage of the taxon, the latitude and longitude coordinates from which the taxon was sampled and body size of the taxon: -```r +```{r} get_trait_from_taxon( data, # data.frame with at least five columns: target taxon, life stage, latitude (dd), longitude (dd) and body size (mm) if trait == "equation" target_taxon, # character string with the column name containing the taxon names @@ -115,5 +128,3 @@ print(dol_df[1,]) print(dplyr::filter(dol_df_equ$data, row == 1)) ``` - - From 39a2290e091ecdbbb8b6b30432fe4d04b8d2fc64 Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 23:32:23 +0200 Subject: [PATCH 6/7] try r-lib/actions/setup-renv@v2 --- .github/workflows/R-CMD-check.yaml | 31 +--------------------------- .github/workflows/test-coverage.yaml | 27 +----------------------- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 6d15865..9cbf618 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -44,36 +44,7 @@ jobs: exit 1 fi shell: bash - - name: Set RENV_PATHS_ROOT - shell: bash - run: | - echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV - - name: Install and activate renv - run: | - install.packages("renv") - renv::activate() - shell: Rscript {0} - - name: Get R and OS version - id: get-version - run: | - cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "") - cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "") - shell: Rscript {0} - - name: Restore Renv package cache - uses: actions/cache@v3 - with: - path: ${{ env.RENV_PATHS_ROOT }} - key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }} - restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}- - - name: Restore packages - shell: Rscript {0} - run: | - if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") - renv::restore() - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::rcmdcheck - needs: check + - uses: r-lib/actions/setup-renv@v2 - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 5921510..e843784 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -21,32 +21,7 @@ jobs: - name: Install OS packages run: | sudo apt install -y libgdal-dev libudunits2-dev - - name: Set RENV_PATHS_ROOT - shell: bash - run: | - echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV - - name: Install and activate renv - run: | - install.packages("renv") - renv::activate() - shell: Rscript {0} - - name: Get R and OS version - id: get-version - run: | - cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "") - cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "") - shell: Rscript {0} - - name: Restore Renv package cache - uses: actions/cache@v3 - with: - path: ${{ env.RENV_PATHS_ROOT }} - key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }} - restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}- - - name: Restore packages - shell: Rscript {0} - run: | - if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") - renv::restore() + - uses: r-lib/actions/setup-renv@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::covr From 7dd2b78fb97debc138553ee79908d613dd9abfec Mon Sep 17 00:00:00 2001 From: Ronald Bergmann Date: Wed, 19 Jul 2023 23:37:57 +0200 Subject: [PATCH 7/7] patch setup-r-dependencies back in --- .github/workflows/R-CMD-check.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 9cbf618..d529b43 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -45,6 +45,10 @@ jobs: fi shell: bash - uses: r-lib/actions/setup-renv@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true