diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 183469fe..e0d8fc05 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -6,7 +6,7 @@ on: pull_request: branches: [main] -name: R-CMD-check +name: R-CMD-check.yaml jobs: R-CMD-check: @@ -38,13 +38,22 @@ jobs: - name: Install macOS system dependencies if: runner.os == 'macOS' - run: brew install gdal proj fribidi + run: brew install gdal proj + + - name: Install Linux system dependencies + if: runner.os == 'Linux' + run: | + sudo apt install \ + libudunits2-dev \ + libgdal-dev \ + libgeos-dev \ + libproj-dev \ - 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/setup-r-dependencies@v2 + # with: + # extra-packages: any::rcmdcheck + # needs: check - uses: r-lib/actions/check-r-package@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index c17d1fe5..17fceb9a 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -6,7 +6,7 @@ on: pull_request: branches: [main, master] -name: test-coverage +name: test-coverage.yaml jobs: test-coverage: @@ -15,7 +15,9 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r@v2 with: @@ -23,10 +25,10 @@ jobs: - uses: r-lib/actions/setup-renv@v2 - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::covr - needs: coverage + # - uses: r-lib/actions/setup-r-dependencies@v2 + # with: + # extra-packages: any::covr + # needs: coverage - name: Test coverage run: | diff --git a/DESCRIPTION b/DESCRIPTION index 46041320..1efe1e1b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -52,5 +52,5 @@ Suggests: pkgdown LinkingTo: Rcpp -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 VignetteBuilder: knitr diff --git a/inst/cpp/pops-core b/inst/cpp/pops-core index 1d3ff980..9345ef10 160000 --- a/inst/cpp/pops-core +++ b/inst/cpp/pops-core @@ -1 +1 @@ -Subproject commit 1d3ff980e4da276527183d6bbf21be271250d9aa +Subproject commit 9345ef10c6aa1a4f30995b5855a6b793b647b597 diff --git a/inst/include/host_pool.hpp b/inst/include/host_pool.hpp index efedc488..ec7221d5 100644 --- a/inst/include/host_pool.hpp +++ b/inst/include/host_pool.hpp @@ -307,8 +307,7 @@ class HostPool : public HostPoolInterface } } else { - dispersers_from_cell = - static_cast(std::floor(lambda * infected_at(row, col))); + dispersers_from_cell = std::lround(lambda * infected_at(row, col)); } return dispersers_from_cell; } diff --git a/man/calibrate.Rd b/man/calibrate.Rd index 931205cd..67a4a1dd 100644 --- a/man/calibrate.Rd +++ b/man/calibrate.Rd @@ -154,14 +154,17 @@ We recommend running at least 1,000 but the greater this number the more accurate the model parameters selected will be.} \item{pest_host_table}{The file path to a csv that has these columns in this order: host, -susceptibility, mortality rate, and mortality time lag as columns with each row being the -species. Host species must be in the same order in the host_file_list, infected_file_list, -pest_host_table rows, and competency_table columns. The host column is only used for metadata -and labeling output files.} +susceptibility_mean, susceptibility_sd, mortality_rate, mortality_rate_mean, +and mortality_time_lag as columns with each row being the species. Host species +must be in the same order in the host_file_list, infected_file_list, +pest_host_table rows, and competency_table columns. The host column is character +string of the species name, and is only used for metadata and labeling output files. +Susceptibility and mortality_rate values must be between 0 and 1.} \item{competency_table}{A csv with the hosts as the first n columns (n being the number of hosts) and the last column being the competency value. Each row is a set of Boolean for host presence -and the competency value (between 0 and 1) for that combination of hosts in a cell.} +and the competency value (between 0 and 1) for that combination of hosts in a cell. +#'} \item{infected_file_list}{paths to raster files with initial infections and standard deviation for each host can be based in 2 formats (a single file with number of hosts or a single file with diff --git a/man/pops.Rd b/man/pops.Rd index 45798c51..03d785f2 100644 --- a/man/pops.Rd +++ b/man/pops.Rd @@ -110,14 +110,17 @@ percent_natural_dispersal, anthropogenic_dispersal_distance, natural kappa, anth network_min_distance, and network_max_distance) Should be 8x8 matrix.} \item{pest_host_table}{The file path to a csv that has these columns in this order: host, -susceptibility, mortality rate, and mortality time lag as columns with each row being the -species. Host species must be in the same order in the host_file_list, infected_file_list, -pest_host_table rows, and competency_table columns. The host column is only used for metadata -and labeling output files.} +susceptibility_mean, susceptibility_sd, mortality_rate, mortality_rate_mean, +and mortality_time_lag as columns with each row being the species. Host species +must be in the same order in the host_file_list, infected_file_list, +pest_host_table rows, and competency_table columns. The host column is character +string of the species name, and is only used for metadata and labeling output files. +Susceptibility and mortality_rate values must be between 0 and 1.} \item{competency_table}{A csv with the hosts as the first n columns (n being the number of hosts) and the last column being the competency value. Each row is a set of Boolean for host presence -and the competency value (between 0 and 1) for that combination of hosts in a cell.} +and the competency value (between 0 and 1) for that combination of hosts in a cell. +#'} \item{temp}{boolean that allows the use of temperature coefficients to modify spread (TRUE or FALSE)} diff --git a/man/pops_model.Rd b/man/pops_model.Rd index 8f50759b..969b053e 100644 --- a/man/pops_model.Rd +++ b/man/pops_model.Rd @@ -93,8 +93,8 @@ pops_model( compatibility option). Default is FALSE.} \item{random_seeds}{vector of random seeds in the order of "disperser_generation", -"natural_dispersal", "anthropogenic_dispersal", "establishment", "weather", "movement", -"overpopulation", "survival_rate", "soil"} +"natural_dispersal", "anthropogenic_dispersal", "establishment", "weather", +"lethal_temperature", "movement", "overpopulation", "survival_rate", "soil"} \item{use_lethal_temperature}{A boolean to answer the question: does your pest or pathogen have a temperature at which it cannot survive? (TRUE or FALSE)} @@ -121,13 +121,16 @@ mortality_tracker for that host.} \item{competency_table}{A csv with the hosts as the first n columns (n being the number of hosts) and the last column being the competency value. Each row is a set of Boolean for host presence -and the competency value (between 0 and 1) for that combination of hosts in a cell.} +and the competency value (between 0 and 1) for that combination of hosts in a cell. +#'} \item{pest_host_table}{The file path to a csv that has these columns in this order: host, -susceptibility, mortality rate, and mortality time lag as columns with each row being the -species. Host species must be in the same order in the host_file_list, infected_file_list, -pest_host_table rows, and competency_table columns. The host column is only used for metadata -and labeling output files.} +susceptibility_mean, susceptibility_sd, mortality_rate, mortality_rate_mean, +and mortality_time_lag as columns with each row being the species. Host species +must be in the same order in the host_file_list, infected_file_list, +pest_host_table rows, and competency_table columns. The host column is character +string of the species name, and is only used for metadata and labeling output files. +Susceptibility and mortality_rate values must be between 0 and 1.} \item{mortality_on}{Boolean to indicate if mortality is used} diff --git a/man/pops_multirun.Rd b/man/pops_multirun.Rd index a5c028e9..b619a7d5 100644 --- a/man/pops_multirun.Rd +++ b/man/pops_multirun.Rd @@ -114,14 +114,17 @@ percent_natural_dispersal, anthropogenic_dispersal_distance, natural kappa, anth network_min_distance, and network_max_distance) Should be 8x8 matrix.} \item{pest_host_table}{The file path to a csv that has these columns in this order: host, -susceptibility, mortality rate, and mortality time lag as columns with each row being the -species. Host species must be in the same order in the host_file_list, infected_file_list, -pest_host_table rows, and competency_table columns. The host column is only used for metadata -and labeling output files.} +susceptibility_mean, susceptibility_sd, mortality_rate, mortality_rate_mean, +and mortality_time_lag as columns with each row being the species. Host species +must be in the same order in the host_file_list, infected_file_list, +pest_host_table rows, and competency_table columns. The host column is character +string of the species name, and is only used for metadata and labeling output files. +Susceptibility and mortality_rate values must be between 0 and 1.} \item{competency_table}{A csv with the hosts as the first n columns (n being the number of hosts) and the last column being the competency value. Each row is a set of Boolean for host presence -and the competency value (between 0 and 1) for that combination of hosts in a cell.} +and the competency value (between 0 and 1) for that combination of hosts in a cell. +#'} \item{temp}{boolean that allows the use of temperature coefficients to modify spread (TRUE or FALSE)} diff --git a/man/validate.Rd b/man/validate.Rd index 722853f2..06875f93 100644 --- a/man/validate.Rd +++ b/man/validate.Rd @@ -106,14 +106,17 @@ If not set uses the # of CPU cores - 1. must be an integer >= 1} calibration function (posterior covariance matrix)} \item{pest_host_table}{The file path to a csv that has these columns in this order: host, -susceptibility, mortality rate, and mortality time lag as columns with each row being the -species. Host species must be in the same order in the host_file_list, infected_file_list, -pest_host_table rows, and competency_table columns. The host column is only used for metadata -and labeling output files.} +susceptibility_mean, susceptibility_sd, mortality_rate, mortality_rate_mean, +and mortality_time_lag as columns with each row being the species. Host species +must be in the same order in the host_file_list, infected_file_list, +pest_host_table rows, and competency_table columns. The host column is character +string of the species name, and is only used for metadata and labeling output files. +Susceptibility and mortality_rate values must be between 0 and 1.} \item{competency_table}{A csv with the hosts as the first n columns (n being the number of hosts) and the last column being the competency value. Each row is a set of Boolean for host presence -and the competency value (between 0 and 1) for that combination of hosts in a cell.} +and the competency value (between 0 and 1) for that combination of hosts in a cell. +#'} \item{infected_file_list}{paths to raster files with initial infections and standard deviation for each host can be based in 2 formats (a single file with number of hosts or a single file with diff --git a/renv.lock b/renv.lock index 55844db0..5c6b2354 100644 --- a/renv.lock +++ b/renv.lock @@ -1,6 +1,6 @@ { "R": { - "Version": "4.3.0", + "Version": "4.4.1", "Repositories": [ { "Name": "CRAN", @@ -11,7 +11,7 @@ "Packages": { "MASS": { "Package": "MASS", - "Version": "7.3-60.0.1", + "Version": "7.3-61", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -22,11 +22,11 @@ "stats", "utils" ], - "Hash": "b765b28387acc8ec9e9c1530713cb19c" + "Hash": "0cafd6f0500e5deba33be22c46bf6055" }, "Matrix": { "Package": "Matrix", - "Version": "1.6-5", + "Version": "1.7-0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -39,7 +39,7 @@ "stats", "utils" ], - "Hash": "8c7115cd3a0e048bda2a7cd110549f7a" + "Hash": "1920b2f11133b12350024297d8a4ff4a" }, "Metrics": { "Package": "Metrics", @@ -70,18 +70,18 @@ }, "Rcpp": { "Package": "Rcpp", - "Version": "1.0.12", + "Version": "1.0.13-1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods", "utils" ], - "Hash": "5ea2700d21e038ace58269ecdbeb9ec0" + "Hash": "6b868847b365672d6c1677b1608da9ed" }, "RcppArmadillo": { "Package": "RcppArmadillo", - "Version": "0.12.8.1.0", + "Version": "14.2.2-1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -91,11 +91,11 @@ "stats", "utils" ], - "Hash": "e78bbbb81a5dcd71a4bd3268d6ede0b1" + "Hash": "9da7c242d94a8419d045f6b3a64b9765" }, "XML": { "Package": "XML", - "Version": "3.99-0.16.1", + "Version": "3.99-0.17", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -103,17 +103,17 @@ "methods", "utils" ], - "Hash": "da3098169c887914551b607c66fe2a28" + "Hash": "bc2a8a1139d8d4bd9c46086708945124" }, "askpass": { "Package": "askpass", - "Version": "1.2.0", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "sys" ], - "Hash": "cad6cf7f1d5f6e906700b9d3e718c796" + "Hash": "c39f4155b3ceb1a9a2799d700fbd4b6a" }, "aws.s3": { "Package": "aws.s3", @@ -155,23 +155,24 @@ }, "brio": { "Package": "brio", - "Version": "1.1.4", + "Version": "1.1.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "68bd2b066e1fe780bbf62fc8bcc36de3" + "Hash": "c1ee497a6d999947c2c224ae46799b1a" }, "bslib": { "Package": "bslib", - "Version": "0.6.2", + "Version": "0.8.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "base64enc", "cachem", + "fastmap", "grDevices", "htmltools", "jquerylib", @@ -182,18 +183,18 @@ "rlang", "sass" ], - "Hash": "7fb73102553e0c8e478bfaa0ccebe479" + "Hash": "b299c6741ca9746fb227debcb0f9fb6c" }, "cachem": { "Package": "cachem", - "Version": "1.0.8", + "Version": "1.1.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "fastmap", "rlang" ], - "Hash": "c35768291560ce302c0a6589f92e837d" + "Hash": "cd9a672193789068eb5a2aad65a0dedf" }, "callr": { "Package": "callr", @@ -210,28 +211,28 @@ }, "cli": { "Package": "cli", - "Version": "3.6.2", + "Version": "3.6.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "1216ac65ac55ec0058a6f75d7ca0fd52" + "Hash": "b21916dd77a27642b447374a5d30ecf3" }, "codetools": { "Package": "codetools", - "Version": "0.2-19", + "Version": "0.2-20", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "c089a619a7fae175d149d89164f8c7d8" + "Hash": "61e097f35917d342622f21cdc79c256e" }, "colorspace": { "Package": "colorspace", - "Version": "2.1-0", + "Version": "2.1-1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -241,14 +242,14 @@ "methods", "stats" ], - "Hash": "f20c47fd52fae58b4e377c37bb8c335b" + "Hash": "d954cb1c57e8d8b756165d7ba18aa55a" }, "commonmark": { "Package": "commonmark", - "Version": "1.9.1", + "Version": "1.9.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "5d8225445acb167abf7797de48b2ee3c" + "Hash": "14eb0596f987c71535d07c3aff814742" }, "covr": { "Package": "covr", @@ -272,17 +273,17 @@ }, "cpp11": { "Package": "cpp11", - "Version": "0.4.7", + "Version": "0.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "5a295d7d963cc5035284dcdbaf334f4e" + "Hash": "9df43854f1c84685d095ed6270b52387" }, "crayon": { "Package": "crayon", - "Version": "1.5.2", + "Version": "1.5.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -290,28 +291,28 @@ "methods", "utils" ], - "Hash": "e8a1e41acf02548751f45c718d55aa6a" + "Hash": "859d96e65ef198fd43e82b9628d593ef" }, "curl": { "Package": "curl", - "Version": "5.2.1", + "Version": "6.0.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "411ca2c03b1ce5f548345d2fc2685f7a" + "Hash": "e8ba62486230951fcd2b881c5be23f96" }, "data.table": { "Package": "data.table", - "Version": "1.15.2", + "Version": "1.16.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "536dfe4ac4093b5d115caed7a1a7223b" + "Hash": "38bbf05fc2503143db4c734a7e5cab66" }, "desc": { "Package": "desc", @@ -343,14 +344,14 @@ }, "digest": { "Package": "digest", - "Version": "0.6.35", + "Version": "0.6.37", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "698ece7ba5a4fa4559e3d537e7ec3d31" + "Hash": "33698c4b3127fc9f506654607fb73676" }, "doParallel": { "Package": "doParallel", @@ -368,7 +369,7 @@ }, "downlit": { "Package": "downlit", - "Version": "0.4.3", + "Version": "0.4.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -384,18 +385,17 @@ "withr", "yaml" ], - "Hash": "14fa1f248b60ed67e1f5418391a17b14" + "Hash": "45a6a596bf0108ee1ff16a040a2df897" }, "evaluate": { "Package": "evaluate", - "Version": "0.23", + "Version": "1.0.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ - "R", - "methods" + "R" ], - "Hash": "daf4a1246be12c1fa8c7705a0935c1a0" + "Hash": "3fd29944b231036ad67c3edb32e02201" }, "fansi": { "Package": "fansi", @@ -411,21 +411,21 @@ }, "farver": { "Package": "farver", - "Version": "2.1.1", + "Version": "2.1.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "8106d78941f34855c440ddb946b8f7a5" + "Hash": "680887028577f3fa2a81e410ed0d6e42" }, "fastmap": { "Package": "fastmap", - "Version": "1.1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "f7736a18de97dea803bde0a2daaafb27" + "Hash": "aa5e1cd11c2d15497494c5292d7ffcc8" }, "fontawesome": { "Package": "fontawesome", - "Version": "0.5.2", + "Version": "0.5.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -433,7 +433,7 @@ "htmltools", "rlang" ], - "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" + "Hash": "bd1297f9b5b1fc1372d19e2c4cd82215" }, "foreach": { "Package": "foreach", @@ -450,14 +450,14 @@ }, "fs": { "Package": "fs", - "Version": "1.6.3", + "Version": "1.6.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "47b5f30c720c23999b913a1a635cf0bb" + "Hash": "7f48af39fa27711ea5fbd183b399920d" }, "generics": { "Package": "generics", @@ -472,7 +472,7 @@ }, "ggplot2": { "Package": "ggplot2", - "Version": "3.5.0", + "Version": "3.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -493,22 +493,22 @@ "vctrs", "withr" ], - "Hash": "52ef83f93f74833007f193b2d4c159a2" + "Hash": "44c6a2f8202d5b7e878ea274b1092426" }, "glue": { "Package": "glue", - "Version": "1.7.0", + "Version": "1.8.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "e0b3a53876554bd45879e596cdb10a52" + "Hash": "5899f1eaa825580172bb56c08266f37c" }, "gtable": { "Package": "gtable", - "Version": "0.3.4", + "Version": "0.3.6", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -517,24 +517,25 @@ "glue", "grid", "lifecycle", - "rlang" + "rlang", + "stats" ], - "Hash": "b29cf3031f49b04ab9c852c912547eef" + "Hash": "de949855009e2d4d0e52a844e30617ae" }, "highr": { "Package": "highr", - "Version": "0.10", + "Version": "0.11", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "xfun" ], - "Hash": "06230136b2d2b9ba5805e1963fa6e890" + "Hash": "d65ba49117ca223614f71b60d85b8ab7" }, "htmltools": { "Package": "htmltools", - "Version": "0.5.8", + "Version": "0.5.8.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -546,7 +547,7 @@ "rlang", "utils" ], - "Hash": "149431ee39aba5bdc264112c8ff94444" + "Hash": "81d371a9cc60640e74e4ab6ac46dcedc" }, "httr": { "Package": "httr", @@ -563,6 +564,27 @@ ], "Hash": "ac107251d9d9fd72f0ca8049988f1d7f" }, + "httr2": { + "Package": "httr2", + "Version": "1.0.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "cli", + "curl", + "glue", + "lifecycle", + "magrittr", + "openssl", + "rappdirs", + "rlang", + "vctrs", + "withr" + ], + "Hash": "5a76da345ed4f3e6430517e08441edaf" + }, "isoband": { "Package": "isoband", "Version": "0.2.7", @@ -597,17 +619,17 @@ }, "jsonlite": { "Package": "jsonlite", - "Version": "1.8.8", + "Version": "1.8.9", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods" ], - "Hash": "e1b9c55281c5adc4dd113652d9e26768" + "Hash": "4e993b65c2c3ffbffce7bb3e2c6f832b" }, "knitr": { "Package": "knitr", - "Version": "1.45", + "Version": "1.49", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -619,7 +641,7 @@ "xfun", "yaml" ], - "Hash": "1ec462871063897135c1bcbe0fc8f07d" + "Hash": "9fcb189926d93c636dea94fbe4f44480" }, "labeling": { "Package": "labeling", @@ -634,7 +656,7 @@ }, "landscapemetrics": { "Package": "landscapemetrics", - "Version": "2.1.1", + "Version": "2.1.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -648,7 +670,7 @@ "terra", "tibble" ], - "Hash": "eefed06a6d4472f65ae0a990928db27d" + "Hash": "8ff90268cbc15a3c7ed5bddf7c53c600" }, "lattice": { "Package": "lattice", @@ -690,7 +712,7 @@ }, "lubridate": { "Package": "lubridate", - "Version": "1.9.3", + "Version": "1.9.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -699,7 +721,7 @@ "methods", "timechange" ], - "Hash": "680ad542fbcf801442c83a6ac5a2126c" + "Hash": "be38bc740fc51783a78edb5a157e4104" }, "magrittr": { "Package": "magrittr", @@ -713,7 +735,7 @@ }, "markdown": { "Package": "markdown", - "Version": "1.12", + "Version": "1.13", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -722,7 +744,7 @@ "utils", "xfun" ], - "Hash": "765cf53992401b3b6c297b69e1edb8bd" + "Hash": "074efab766a9d6360865ad39512f2a7e" }, "memoise": { "Package": "memoise", @@ -764,14 +786,14 @@ }, "munsell": { "Package": "munsell", - "Version": "0.5.0", + "Version": "0.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "colorspace", "methods" ], - "Hash": "6dfe8bf774944bd5595785e3229d8771" + "Hash": "4fd8900853b746af55b81fda99da7695" }, "nlme": { "Package": "nlme", @@ -789,13 +811,13 @@ }, "openssl": { "Package": "openssl", - "Version": "2.1.1", + "Version": "2.2.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "askpass" ], - "Hash": "2a0dc8c6adfb6f032e4d4af82d258ab5" + "Hash": "d413e0fef796c9401a4419485f709ca1" }, "pillar": { "Package": "pillar", @@ -816,7 +838,7 @@ }, "pkgbuild": { "Package": "pkgbuild", - "Version": "1.4.4", + "Version": "1.4.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -827,7 +849,7 @@ "desc", "processx" ], - "Hash": "a29e8e134a460a01e0ca67a4763c595b" + "Hash": "30eaaab94db72652e72e3475c1b55278" }, "pkgconfig": { "Package": "pkgconfig", @@ -841,7 +863,7 @@ }, "pkgdown": { "Package": "pkgdown", - "Version": "2.0.7", + "Version": "2.1.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -852,11 +874,11 @@ "desc", "digest", "downlit", + "fontawesome", "fs", - "httr", + "httr2", "jsonlite", - "magrittr", - "memoise", + "openssl", "purrr", "ragg", "rlang", @@ -867,28 +889,29 @@ "xml2", "yaml" ], - "Hash": "16fa15449c930bf3a7761d3c68f8abf9" + "Hash": "df2912d5873422b55a13002510f02c9f" }, "pkgload": { "Package": "pkgload", - "Version": "1.3.4", + "Version": "1.4.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "cli", - "crayon", "desc", "fs", "glue", + "lifecycle", "methods", "pkgbuild", + "processx", "rlang", "rprojroot", "utils", "withr" ], - "Hash": "876c618df5ae610be84356d5d7a5d124" + "Hash": "2ec30ffbeec83da57655b850cf2d3e0e" }, "praise": { "Package": "praise", @@ -922,14 +945,14 @@ }, "ps": { "Package": "ps", - "Version": "1.7.6", + "Version": "1.8.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "dd2b9319ee0656c8acf45c7f40c59de7" + "Hash": "b4404b1de13758dea1c0484ad0d48563" }, "purrr": { "Package": "purrr", @@ -948,7 +971,7 @@ }, "qpdf": { "Package": "qpdf", - "Version": "1.3.3", + "Version": "1.3.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -956,18 +979,18 @@ "askpass", "curl" ], - "Hash": "479ebe6dca0a57c63d306e1b6a4bf30c" + "Hash": "949ca99a6d20c4ff8212026b3b5559af" }, "ragg": { "Package": "ragg", - "Version": "1.3.0", + "Version": "1.3.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "systemfonts", "textshaping" ], - "Hash": "082e1a198e3329d571f4448ef0ede4bc" + "Hash": "0595fe5e47357111f29ad19101c7d271" }, "rappdirs": { "Package": "rappdirs", @@ -1001,16 +1024,6 @@ ], "Hash": "8f25ebe2ec38b1f2aef3b0d2ef76f6c4" }, - "rematch2": { - "Package": "rematch2", - "Version": "2.1.2", - "Source": "Repository", - "Repository": "CRAN", - "Requirements": [ - "tibble" - ], - "Hash": "76c9e04c712a05848ae7a23d2f170a40" - }, "remotes": { "Package": "remotes", "Version": "2.5.0", @@ -1047,14 +1060,14 @@ }, "rlang": { "Package": "rlang", - "Version": "1.1.3", + "Version": "1.1.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "42548638fae05fd9a9b5f3f437fbbbe2" + "Hash": "3eec01f8b1dee337674b2e34ab1f9bc1" }, "rlist": { "Package": "rlist", @@ -1072,7 +1085,7 @@ }, "rmarkdown": { "Package": "rmarkdown", - "Version": "2.26", + "Version": "2.29", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1091,7 +1104,7 @@ "xfun", "yaml" ], - "Hash": "9b148e7f95d33aac01f31282d49e4f44" + "Hash": "df99277f63d01c34e95e3d2f06a79736" }, "rprojroot": { "Package": "rprojroot", @@ -1152,25 +1165,26 @@ }, "sys": { "Package": "sys", - "Version": "3.4.2", + "Version": "3.4.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "3a1be13d68d47a8cd0bfd74739ca1555" + "Hash": "de342ebfebdbf40477d0758d05426646" }, "systemfonts": { "Package": "systemfonts", - "Version": "1.0.6", + "Version": "1.1.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", - "cpp11" + "cpp11", + "lifecycle" ], - "Hash": "6d538cff441f0f1f36db2209ac7495ac" + "Hash": "213b6b8ed5afbf934843e6c3b090d418" }, "terra": { "Package": "terra", - "Version": "1.7-71", + "Version": "1.8-5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1178,11 +1192,11 @@ "Rcpp", "methods" ], - "Hash": "e8611881ab70a4fb7a1f629b31e6fcff" + "Hash": "6e3f2c53b58161327fe5787fe1a63d02" }, "testthat": { "Package": "testthat", - "Version": "3.2.1", + "Version": "3.2.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1207,19 +1221,20 @@ "waldo", "withr" ], - "Hash": "4767a686ebe986e6cb01d075b3f09729" + "Hash": "6773967afbe2f74c87021e72c1bb05c0" }, "textshaping": { "Package": "textshaping", - "Version": "0.3.7", + "Version": "0.4.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "cpp11", + "lifecycle", "systemfonts" ], - "Hash": "997aac9ad649e0ef3b97f96cddd5622b" + "Hash": "573e0d015b7fc3e555f83e254cad7533" }, "tibble": { "Package": "tibble", @@ -1253,13 +1268,13 @@ }, "tinytex": { "Package": "tinytex", - "Version": "0.50", + "Version": "0.54", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "xfun" ], - "Hash": "be7a76845222ad20adb761f462eed3ea" + "Hash": "3ec7e3ddcacc2d34a9046941222bf94d" }, "utf8": { "Package": "utf8", @@ -1297,21 +1312,18 @@ }, "waldo": { "Package": "waldo", - "Version": "0.5.2", + "Version": "0.6.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "cli", "diffobj", - "fansi", "glue", "methods", - "rematch2", - "rlang", - "tibble" + "rlang" ], - "Hash": "c7d3fd6d29ab077cbac8f0e2751449e6" + "Hash": "52f574062a7b66e56926988c3fbdb3b7" }, "whisker": { "Package": "whisker", @@ -1322,7 +1334,7 @@ }, "withr": { "Package": "withr", - "Version": "3.0.0", + "Version": "3.0.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1330,19 +1342,20 @@ "grDevices", "graphics" ], - "Hash": "d31b6c62c10dcf11ec530ca6b0dd5d35" + "Hash": "cc2d62c76458d425210d1eb1478b30b4" }, "xfun": { "Package": "xfun", - "Version": "0.43", + "Version": "0.49", "Source": "Repository", "Repository": "CRAN", "Requirements": [ + "R", "grDevices", "stats", "tools" ], - "Hash": "ab6371d8653ce5f2f9290f4ec7b42a8e" + "Hash": "8687398773806cfff9401a2feca96298" }, "xml2": { "Package": "xml2", @@ -1359,21 +1372,21 @@ }, "xopen": { "Package": "xopen", - "Version": "1.0.0", + "Version": "1.0.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "processx" ], - "Hash": "6c85f015dee9cc7710ddd20f86881f58" + "Hash": "423df1e86d5533fcb73c6b02b4923b49" }, "yaml": { "Package": "yaml", - "Version": "2.3.8", + "Version": "2.3.10", "Source": "Repository", "Repository": "CRAN", - "Hash": "29240487a071f535f5e5d5a323b7afbd" + "Hash": "51dab85c6c98e50a18d7551e9d49f76c" } } } diff --git a/renv/activate.R b/renv/activate.R index a0639113..9b2e7f18 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -3,10 +3,26 @@ local({ # the requested version of renv version <- "1.0.5" + attr(version, "sha") <- NULL # the project directory project <- getwd() + # use start-up diagnostics if enabled + diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE") + if (diagnostics) { + start <- Sys.time() + profile <- tempfile("renv-startup-", fileext = ".Rprof") + utils::Rprof(profile) + on.exit({ + utils::Rprof(NULL) + elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L) + writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed))) + writeLines(sprintf("- Profile: %s", profile)) + print(utils::summaryRprof(profile)) + }, add = TRUE) + } + # figure out whether the autoloader is enabled enabled <- local({ @@ -15,6 +31,14 @@ local({ if (!is.null(override)) return(override) + # if we're being run in a context where R_LIBS is already set, + # don't load -- presumably we're being run as a sub-process and + # the parent process has already set up library paths for us + rcmd <- Sys.getenv("R_CMD", unset = NA) + rlibs <- Sys.getenv("R_LIBS", unset = NA) + if (!is.na(rlibs) && !is.na(rcmd)) + return(FALSE) + # next, check environment variables # TODO: prefer using the configuration one in the future envvars <- c( @@ -34,9 +58,22 @@ local({ }) - if (!enabled) + # bail if we're not enabled + if (!enabled) { + + # if we're not enabled, we might still need to manually load + # the user profile here + profile <- Sys.getenv("R_PROFILE_USER", unset = "~/.Rprofile") + if (file.exists(profile)) { + cfg <- Sys.getenv("RENV_CONFIG_USER_PROFILE", unset = "TRUE") + if (tolower(cfg) %in% c("true", "t", "1")) + sys.source(profile, envir = globalenv()) + } + return(FALSE) + } + # avoid recursion if (identical(getOption("renv.autoloader.running"), TRUE)) { warning("ignoring recursive attempt to run renv autoloader") @@ -60,25 +97,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 +195,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 +238,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 +329,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 +345,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 +405,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 +412,11 @@ local({ condition = identity ) - if (identical(status, 0L)) { - message("OK") + if (identical(status, 0L)) return(destfile) - } } - message("FAILED") return(FALSE) } @@ -368,7 +439,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 +448,7 @@ local({ } - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) - + catf("- Using local tarball '%s'.", tarball) tarball } @@ -407,8 +475,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 +484,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 +590,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 +800,62 @@ 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 + # + # avoid passing lib.loc to `packageDescription()` below, since R will + # use the loaded version of the package by default anyhow. note that + # this function should only be called after 'renv' is loaded + # https://github.com/rstudio/renv/issues/1625 + description <- description %||% packageDescription("renv") - # 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-") @@ -718,7 +879,7 @@ local({ hooks <- getHook("renv::autoload") for (hook in hooks) if (is.function(hook)) - tryCatch(hook(), error = warning) + tryCatch(hook(), error = warnify) # load the project renv::load(project) @@ -859,6 +1020,40 @@ local({ } + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { + sha <- sha %||% attr(version, "sha", exact = TRUE) + parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = "") + } + + renv_bootstrap_exec <- function(project, libpath, version) { + if (!renv_bootstrap_load(project, libpath, version)) + renv_bootstrap_run(version, libpath) + } + + 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_json_read <- function(file = NULL, text = NULL) { @@ -867,7 +1062,7 @@ local({ # if jsonlite is loaded, use that instead if ("jsonlite" %in% loadedNamespaces()) { - json <- catch(renv_json_read_jsonlite(file, text)) + json <- tryCatch(renv_json_read_jsonlite(file, text), error = identity) if (!inherits(json, "error")) return(json) @@ -876,7 +1071,7 @@ local({ } # otherwise, fall back to the default JSON reader - json <- catch(renv_json_read_default(file, text)) + json <- tryCatch(renv_json_read_default(file, text), error = identity) if (!inherits(json, "error")) return(json) @@ -889,14 +1084,14 @@ local({ } renv_json_read_jsonlite <- function(file = NULL, text = NULL) { - text <- paste(text %||% read(file), collapse = "\n") + text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n") jsonlite::fromJSON(txt = text, simplifyVector = FALSE) } renv_json_read_default <- function(file = NULL, text = NULL) { # find strings in the JSON - text <- paste(text %||% read(file), collapse = "\n") + text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n") pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' locs <- gregexpr(pattern, text, perl = TRUE)[[1]] @@ -944,14 +1139,14 @@ local({ map <- as.list(map) # remap strings in object - remapped <- renv_json_remap(json, map) + remapped <- renv_json_read_remap(json, map) # evaluate eval(remapped, envir = baseenv()) } - renv_json_remap <- function(json, map) { + renv_json_read_remap <- function(json, map) { # fix names if (!is.null(names(json))) { @@ -978,7 +1173,7 @@ local({ # recurse if (is.recursive(json)) { for (i in seq_along(json)) { - json[i] <- list(renv_json_remap(json[[i]], map)) + json[i] <- list(renv_json_read_remap(json[[i]], map)) } } @@ -998,35 +1193,9 @@ local({ # construct full libpath libpath <- file.path(root, prefix) - # attempt to load - 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) - - # 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()) - } - - # 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." - ) + # run bootstrap code + renv_bootstrap_exec(project, libpath, version) - warning(paste(msg, collapse = "\n"), call. = FALSE) + invisible() })