diff --git a/.Rbuildignore b/.Rbuildignore index 9f98c75..0b757c8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,6 +9,8 @@ $run_dev.* ^LICENSE\.md$ ^README\.Rmd$ ^app\.R$ +^R/_disable_autoload\.R$ ^rsconnect$ +^\.rscignore$ ^\.github$ ^deploy$ diff --git a/.github/workflows/ci-cd-renv.yml b/.github/workflows/ci-cd-renv.yml index daa2f09..899373e 100644 --- a/.github/workflows/ci-cd-renv.yml +++ b/.github/workflows/ci-cd-renv.yml @@ -15,6 +15,11 @@ on: schedule: - cron: '0 0 1 * *' +# Avoid concurrent deployments from both workflows by running one at a time +# (specific for ShinyCICD maintenance) +concurrency: + group: shinyapps-${{ github.ref }} + jobs: CI-CD: runs-on: ${{ matrix.config.os }} @@ -26,7 +31,7 @@ jobs: # single OS and R version, aligned with the target deployment environment matrix: config: - - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'renv'} env: # Access token for GitHub @@ -43,18 +48,21 @@ jobs: uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} - # Enable RStudio Package Manager to speed up package installation - use-public-rspm: true + # No RStudio Package Manager to respect renv.lock + use-public-rspm: false - name: Install system dependencies # This is not taken care of (yet) by r-lib/actions/setup-renv - # Package distro used to get the distro for the used ubuntu-latest + # See https://github.com/r-lib/actions/issues/785 run: | - Rscript -e "install.packages(c('remotes', 'distro'))" - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(with(distro::distro(), remotes::system_requirements(id, short_version)))') + # We rely on pkgdepends from the library embedded in pak + install.packages("pak", repos = "https://r-lib.github.io/p/pak/stable/") + install.packages("jsonlite") + .libPaths(c(system.file("library", package = "pak"), .libPaths())) + pkgdepends::new_pkg_installation_proposal( + names(jsonlite::read_json("renv.lock")$Packages), config = list(dependencies = FALSE) + )$solve()$install_sysreqs() + shell: Rscript {0} - name: Activate renv and restore packages with cache uses: r-lib/actions/setup-renv@v2 @@ -68,7 +76,7 @@ jobs: - name: Deploy to shinyapps.io # Continuous deployment only for pushes to the main / master branch - if: false && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' env: SHINYAPPS_ACCOUNT: ${{ secrets.SHINYAPPS_ACCOUNT }} SHINYAPPS_TOKEN: ${{ secrets.SHINYAPPS_TOKEN }} diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 7c59219..ddd662a 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -15,6 +15,11 @@ on: schedule: - cron: '0 0 1 * *' +# Avoid concurrent deployments from both workflows by running one at a time +# (specific for ShinyCICD maintenance) +concurrency: + group: shinyapps-${{ github.ref }} + jobs: CI-CD: runs-on: ${{ matrix.config.os }} diff --git a/.rscignore b/.rscignore new file mode 100644 index 0000000..f3c59a5 --- /dev/null +++ b/.rscignore @@ -0,0 +1 @@ +renv.lock diff --git a/R/_disable_autoload.R b/R/_disable_autoload.R new file mode 100644 index 0000000..a8c9436 --- /dev/null +++ b/R/_disable_autoload.R @@ -0,0 +1,3 @@ +# Disabling shiny autoload + +# See ?shiny::loadSupport for more information diff --git a/R/app_server.R b/R/app_server.R index 1de0b84..c4575da 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -8,7 +8,7 @@ app_server <- function(input, output, session) { output$distPlot <- renderPlot({ # generate bins based on input$bins from ui.R - x <- faithful[, 2] + x <- datasets::faithful[, 2] bins <- seq(min(x), max(x), length.out = input$bins + 1) # draw the histogram with the specified number of bins diff --git a/ShinyCICD.Rproj b/ShinyCICD.Rproj index 497f8bf..aad884d 100644 --- a/ShinyCICD.Rproj +++ b/ShinyCICD.Rproj @@ -1,7 +1,7 @@ Version: 1.0 -RestoreWorkspace: Default -SaveWorkspace: Default +RestoreWorkspace: No +SaveWorkspace: No AlwaysSaveHistory: Default EnableCodeIndexing: Yes diff --git a/deploy/deploy-shinyapps.R b/deploy/deploy-shinyapps.R index 38a13e4..efe8248 100644 --- a/deploy/deploy-shinyapps.R +++ b/deploy/deploy-shinyapps.R @@ -1,8 +1,20 @@ # deploy/deploy-shinyapps.R # usethis::use_build_ignore("deploy") -rsconnect::setAccountInfo( - Sys.getenv("SHINYAPPS_ACCOUNT"), - Sys.getenv("SHINYAPPS_TOKEN"), - Sys.getenv("SHINYAPPS_SECRET") +if (!interactive()) { + rsconnect::setAccountInfo( + Sys.getenv("SHINYAPPS_ACCOUNT"), + Sys.getenv("SHINYAPPS_TOKEN"), + Sys.getenv("SHINYAPPS_SECRET") + ) +} +# Add here any additional files/directories the app needs +app_files = c( + "app.R", + "DESCRIPTION", + "NAMESPACE", + "R/", + "inst/" +) +rsconnect::deployApp( + appName = "ShinyCICD", appFiles = app_files, forceUpdate = TRUE ) -rsconnect::deployApp(appName = "ShinyCICD") diff --git a/renv.lock b/renv.lock index b1b6e4b..d4a419d 100644 --- a/renv.lock +++ b/renv.lock @@ -1,6 +1,6 @@ { "R": { - "Version": "4.2.2", + "Version": "4.3.2", "Repositories": [ { "Name": "CRAN", @@ -14,499 +14,433 @@ "Version": "2.5.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "470851b6d5d0ac559e9d01bb352b4021", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "470851b6d5d0ac559e9d01bb352b4021" }, "Rcpp": { "Package": "Rcpp", - "Version": "1.0.9", + "Version": "1.0.12", "Source": "Repository", "Repository": "CRAN", - "Hash": "e9c08b94391e9f3f97355841229124f2", - "Requirements": [] + "Requirements": [ + "methods", + "utils" + ], + "Hash": "5ea2700d21e038ace58269ecdbeb9ec0" }, "askpass": { "Package": "askpass", - "Version": "1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "e8a22846fff485f0be3770c2da758713", "Requirements": [ "sys" - ] + ], + "Hash": "cad6cf7f1d5f6e906700b9d3e718c796" }, "attempt": { "Package": "attempt", "Version": "0.3.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "d7421bb5dfeb2676b9e4a5a60c2fcfd2", "Requirements": [ "rlang" - ] + ], + "Hash": "d7421bb5dfeb2676b9e4a5a60c2fcfd2" }, "base64enc": { "Package": "base64enc", "Version": "0.1-3", "Source": "Repository", "Repository": "CRAN", - "Hash": "543776ae6848fde2f48ff3816d0628bc", - "Requirements": [] - }, - "brew": { - "Package": "brew", - "Version": "1.0-8", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "d69a786e85775b126bddbee185ae6084", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "543776ae6848fde2f48ff3816d0628bc" }, "brio": { "Package": "brio", - "Version": "1.1.3", + "Version": "1.1.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "976cf154dfb043c012d87cddd8bca363", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "68bd2b066e1fe780bbf62fc8bcc36de3" }, "bslib": { "Package": "bslib", - "Version": "0.4.2", + "Version": "0.6.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "a7fbf03946ad741129dc81098722fca1", "Requirements": [ + "R", "base64enc", "cachem", + "grDevices", "htmltools", "jquerylib", "jsonlite", + "lifecycle", "memoise", "mime", "rlang", "sass" - ] + ], + "Hash": "c0d8599494bc7fb408cd206bbdd9cab0" }, "cachem": { "Package": "cachem", - "Version": "1.0.6", + "Version": "1.0.8", "Source": "Repository", "Repository": "CRAN", - "Hash": "648c5b3d71e6a37e3043617489a0a0e9", "Requirements": [ "fastmap", "rlang" - ] + ], + "Hash": "c35768291560ce302c0a6589f92e837d" }, "callr": { "Package": "callr", "Version": "3.7.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "9b2191ede20fa29828139b9900922e51", "Requirements": [ + "R", "R6", - "processx" - ] + "processx", + "utils" + ], + "Hash": "9b2191ede20fa29828139b9900922e51" }, "cli": { "Package": "cli", - "Version": "3.6.0", + "Version": "3.6.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "3177a5a16c243adc199ba33117bd9657", - "Requirements": [] - }, - "clipr": { - "Package": "clipr", - "Version": "0.8.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "3f038e5ac7f41d4ac41ce658c85e3042", - "Requirements": [] + "Requirements": [ + "R", + "utils" + ], + "Hash": "1216ac65ac55ec0058a6f75d7ca0fd52" }, "commonmark": { "Package": "commonmark", - "Version": "1.8.1", + "Version": "1.9.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "b6e3e947d1d7ebf3d2bdcea1bde63fe7", - "Requirements": [] + "Hash": "d691c61bff84bd63c383874d2d0c3307" }, "config": { "Package": "config", - "Version": "0.3.1", + "Version": "0.3.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "31d77b09f63550cee9ecb5a08bf76e8f", "Requirements": [ "yaml" - ] - }, - "cpp11": { - "Package": "cpp11", - "Version": "0.4.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "ed588261931ee3be2c700d22e94a29ab", - "Requirements": [] + ], + "Hash": "8b7222e9d9eb5178eea545c0c4d33fc2" }, "crayon": { "Package": "crayon", "Version": "1.5.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "e8a1e41acf02548751f45c718d55aa6a", - "Requirements": [] - }, - "credentials": { - "Package": "credentials", - "Version": "1.3.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "93762d0a34d78e6a025efdbfb5c6bb41", "Requirements": [ - "askpass", - "curl", - "jsonlite", - "openssl", - "sys" - ] + "grDevices", + "methods", + "utils" + ], + "Hash": "e8a1e41acf02548751f45c718d55aa6a" }, "curl": { "Package": "curl", - "Version": "5.0.0", + "Version": "5.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "e4f97056611e8e6b8b852d13b7400cf1", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "ce88d13c0b10fe88a37d9c59dba2d7f9" }, "desc": { "Package": "desc", - "Version": "1.4.2", + "Version": "1.4.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "6b9602c7ebbe87101a9c8edb6e8b6d21", "Requirements": [ + "R", "R6", "cli", - "rprojroot" - ] + "utils" + ], + "Hash": "99b79fcbd6c4d1ce087f5c5c758b384f" }, "diffobj": { "Package": "diffobj", "Version": "0.3.5", "Source": "Repository", "Repository": "CRAN", - "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8", "Requirements": [ - "crayon" - ] + "R", + "crayon", + "methods", + "stats", + "tools", + "utils" + ], + "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8" }, "digest": { "Package": "digest", - "Version": "0.6.31", + "Version": "0.6.33", "Source": "Repository", "Repository": "CRAN", - "Hash": "8b708f296afd9ae69f450f9640be8990", - "Requirements": [] + "Requirements": [ + "R", + "utils" + ], + "Hash": "b18a9cf3c003977b0cc49d5e76ebe48d" }, "ellipsis": { "Package": "ellipsis", "Version": "0.3.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077", "Requirements": [ + "R", "rlang" - ] + ], + "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077" }, "evaluate": { "Package": "evaluate", - "Version": "0.20", + "Version": "0.23", "Source": "Repository", "Repository": "CRAN", - "Hash": "4b68aa51edd89a0e044a66e75ae3cc6c", - "Requirements": [] + "Requirements": [ + "R", + "methods" + ], + "Hash": "daf4a1246be12c1fa8c7705a0935c1a0" }, "fansi": { "Package": "fansi", - "Version": "1.0.3", + "Version": "1.0.6", "Source": "Repository", "Repository": "CRAN", - "Hash": "83a8afdbe71839506baa9f90eebad7ec", - "Requirements": [] + "Requirements": [ + "R", + "grDevices", + "utils" + ], + "Hash": "962174cf2aeb5b9eea581522286a911f" }, "fastmap": { "Package": "fastmap", - "Version": "1.1.0", + "Version": "1.1.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "77bd60a6157420d4ffa93b27cf6a58b8", - "Requirements": [] + "Hash": "f7736a18de97dea803bde0a2daaafb27" }, "fontawesome": { "Package": "fontawesome", - "Version": "0.4.0", + "Version": "0.5.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "c5a628c2570aa86a96cc6ef739d8bfda", "Requirements": [ + "R", "htmltools", "rlang" - ] + ], + "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" }, "fs": { "Package": "fs", - "Version": "1.5.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "7c89603d81793f0d5486d91ab1fc6f1d", - "Requirements": [] - }, - "gert": { - "Package": "gert", - "Version": "1.9.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "9122b3958e749badb5c939f498038b57", - "Requirements": [ - "askpass", - "credentials", - "openssl", - "rstudioapi", - "sys", - "zip" - ] - }, - "gh": { - "Package": "gh", - "Version": "1.3.1", + "Version": "1.6.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "b6a12054ee13dce0f6696c019c10e539", "Requirements": [ - "cli", - "gitcreds", - "httr", - "ini", - "jsonlite" - ] - }, - "gitcreds": { - "Package": "gitcreds", - "Version": "0.1.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "ab08ac61f3e1be454ae21911eb8bc2fe", - "Requirements": [] + "R", + "methods" + ], + "Hash": "47b5f30c720c23999b913a1a635cf0bb" }, "glue": { "Package": "glue", - "Version": "1.6.2", + "Version": "1.7.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "4f2596dfb05dac67b9dc558e5c6fba2e", - "Requirements": [] + "Requirements": [ + "R", + "methods" + ], + "Hash": "e0b3a53876554bd45879e596cdb10a52" }, "golem": { "Package": "golem", - "Version": "0.3.5", + "Version": "0.4.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "c4fbd853653f38cccdd009d75abb344c", "Requirements": [ + "R", "attempt", - "cli", "config", - "crayon", - "desc", - "fs", "here", "htmltools", - "pkgload", - "roxygen2", - "rstudioapi", + "rlang", "shiny", - "usethis", + "utils", "yaml" - ] + ], + "Hash": "dc12172dc35c6c80e18b430dc546fc24" }, "here": { "Package": "here", "Version": "1.0.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "24b224366f9c2e7534d2344d10d59211", "Requirements": [ "rprojroot" - ] - }, - "highr": { - "Package": "highr", - "Version": "0.10", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "06230136b2d2b9ba5805e1963fa6e890", - "Requirements": [ - "xfun" - ] + ], + "Hash": "24b224366f9c2e7534d2344d10d59211" }, "htmltools": { "Package": "htmltools", - "Version": "0.5.4", + "Version": "0.5.7", "Source": "Repository", "Repository": "CRAN", - "Hash": "9d27e99cc90bd701c0a7a63e5923f9b7", "Requirements": [ + "R", "base64enc", "digest", "ellipsis", "fastmap", - "rlang" - ] + "grDevices", + "rlang", + "utils" + ], + "Hash": "2d7b3857980e0e0d0a1fd6f11928ab0f" }, "httpuv": { "Package": "httpuv", - "Version": "1.6.8", + "Version": "1.6.13", "Source": "Repository", "Repository": "CRAN", - "Hash": "08e611aee165b27f8ff18770285fb535", "Requirements": [ + "R", "R6", "Rcpp", "later", - "promises" - ] - }, - "httr": { - "Package": "httr", - "Version": "1.4.4", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "57557fac46471f0dbbf44705cc6a5c8c", - "Requirements": [ - "R6", - "curl", - "jsonlite", - "mime", - "openssl" - ] - }, - "ini": { - "Package": "ini", - "Version": "0.3.1", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "6154ec2223172bce8162d4153cda21f7", - "Requirements": [] + "promises", + "utils" + ], + "Hash": "d23d2879001f3d82ee9dc38a9ef53c4c" }, "jquerylib": { "Package": "jquerylib", "Version": "0.1.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "5aab57a3bd297eee1c1d862735972182", "Requirements": [ "htmltools" - ] + ], + "Hash": "5aab57a3bd297eee1c1d862735972182" }, "jsonlite": { "Package": "jsonlite", - "Version": "1.8.4", + "Version": "1.8.8", "Source": "Repository", "Repository": "CRAN", - "Hash": "a4269a09a9b865579b2635c77e572374", - "Requirements": [] - }, - "knitr": { - "Package": "knitr", - "Version": "1.41", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "6d4971f3610e75220534a1befe81bc92", "Requirements": [ - "evaluate", - "highr", - "stringr", - "xfun", - "yaml" - ] + "methods" + ], + "Hash": "e1b9c55281c5adc4dd113652d9e26768" }, "later": { "Package": "later", - "Version": "1.3.0", + "Version": "1.3.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "7e7b457d7766bc47f2a5f21cc2984f8e", "Requirements": [ "Rcpp", "rlang" - ] + ], + "Hash": "a3e051d405326b8b0012377434c62b37" }, "lifecycle": { "Package": "lifecycle", - "Version": "1.0.3", + "Version": "1.0.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "001cecbeac1cff9301bdc3775ee46a86", "Requirements": [ + "R", "cli", "glue", "rlang" - ] + ], + "Hash": "b8552d117e1b808b09a832f589b79035" }, "magrittr": { "Package": "magrittr", "Version": "2.0.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "7ce2733a9826b3aeb1775d56fd305472", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "7ce2733a9826b3aeb1775d56fd305472" }, "memoise": { "Package": "memoise", "Version": "2.0.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c", "Requirements": [ "cachem", "rlang" - ] + ], + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" }, "mime": { "Package": "mime", "Version": "0.12", "Source": "Repository", "Repository": "CRAN", - "Hash": "18e9c28c1d3ca1560ce30658b22ce104", - "Requirements": [] + "Requirements": [ + "tools" + ], + "Hash": "18e9c28c1d3ca1560ce30658b22ce104" }, "openssl": { "Package": "openssl", - "Version": "2.0.5", + "Version": "2.1.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "b04c27110bf367b4daa93f34f3d58e75", "Requirements": [ "askpass" - ] + ], + "Hash": "2a0dc8c6adfb6f032e4d4af82d258ab5" }, "packrat": { "Package": "packrat", - "Version": "0.9.0", + "Version": "0.9.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "2735eb4b51c302014f53acbb3c80a65f", - "Requirements": [] + "Requirements": [ + "R", + "tools", + "utils" + ], + "Hash": "55ddd2d4a1959535f18393478b0c14a6" }, "pillar": { "Package": "pillar", - "Version": "1.8.1", + "Version": "1.9.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "f2316df30902c81729ae9de95ad5a608", "Requirements": [ "cli", "fansi", @@ -514,199 +448,205 @@ "lifecycle", "rlang", "utf8", + "utils", "vctrs" - ] + ], + "Hash": "15da5a8412f317beeee6175fbc76f4bb" + }, + "pkgbuild": { + "Package": "pkgbuild", + "Version": "1.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "callr", + "cli", + "desc", + "processx" + ], + "Hash": "c0143443203205e6a2760ce553dafc24" }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "01f28d4278f15c76cddbea05899c5d6f", - "Requirements": [] + "Requirements": [ + "utils" + ], + "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, "pkgload": { "Package": "pkgload", - "Version": "1.3.2", + "Version": "1.3.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "6b0c222c5071efe0f3baf3dae9aa40e2", "Requirements": [ + "R", "cli", "crayon", "desc", "fs", "glue", + "methods", + "pkgbuild", "rlang", "rprojroot", + "utils", "withr" - ] + ], + "Hash": "903d68319ae9923fb2e2ee7fa8230b91" }, "praise": { "Package": "praise", "Version": "1.0.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "a555924add98c99d2f411e37e7d25e9f", - "Requirements": [] + "Hash": "a555924add98c99d2f411e37e7d25e9f" }, "processx": { "Package": "processx", - "Version": "3.8.0", + "Version": "3.8.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "a33ee2d9bf07564efb888ad98410da84", "Requirements": [ + "R", "R6", - "ps" - ] + "ps", + "utils" + ], + "Hash": "82d48b1aec56084d9438dbf98087a7e9" }, "promises": { "Package": "promises", - "Version": "1.2.0.1", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "4ab2c43adb4d4699cf3690acd378d75d", "Requirements": [ "R6", "Rcpp", + "fastmap", "later", "magrittr", - "rlang" - ] + "rlang", + "stats" + ], + "Hash": "0d8a15c9d000970ada1ab21405387dee" }, "ps": { "Package": "ps", - "Version": "1.7.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "68dd03d98a5efd1eb3012436de45ba83", - "Requirements": [] - }, - "purrr": { - "Package": "purrr", - "Version": "1.0.1", + "Version": "1.7.5", "Source": "Repository", "Repository": "CRAN", - "Hash": "d71c815267c640f17ddbf7f16144b4bb", "Requirements": [ - "cli", - "lifecycle", - "magrittr", - "rlang", - "vctrs" - ] + "R", + "utils" + ], + "Hash": "709d852d33178db54b17c722e5b1e594" }, "rappdirs": { "Package": "rappdirs", "Version": "0.3.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "5e3c5dc0b071b21fa128676560dbe94d", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" }, "rematch2": { "Package": "rematch2", "Version": "2.1.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "76c9e04c712a05848ae7a23d2f170a40", "Requirements": [ "tibble" - ] + ], + "Hash": "76c9e04c712a05848ae7a23d2f170a40" }, "renv": { "Package": "renv", - "Version": "0.16.0", + "Version": "1.0.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "c9e8442ab69bc21c9697ecf856c1e6c7", - "Requirements": [] + "Requirements": [ + "utils" + ], + "Hash": "41b847654f567341725473431dd0d5ab" }, "rlang": { "Package": "rlang", - "Version": "1.0.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "4ed1f8336c8d52c3e750adcdc57228a7", - "Requirements": [] - }, - "roxygen2": { - "Package": "roxygen2", - "Version": "7.2.3", + "Version": "1.1.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "7b153c746193b143c14baa072bae4e27", "Requirements": [ - "R6", - "brew", - "cli", - "commonmark", - "cpp11", - "desc", - "knitr", - "pkgload", - "purrr", - "rlang", - "stringi", - "stringr", - "withr", - "xml2" - ] + "R", + "utils" + ], + "Hash": "42548638fae05fd9a9b5f3f437fbbbe2" }, "rprojroot": { "Package": "rprojroot", - "Version": "2.0.3", + "Version": "2.0.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "1de7ab598047a87bba48434ba35d497d", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "4c8415e0ec1e29f3f4f6fc108bef0144" }, "rsconnect": { "Package": "rsconnect", - "Version": "0.8.29", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "fe178fc15af80952f546aafedf655b36", "Requirements": [ + "R", + "cli", "curl", "digest", "jsonlite", + "lifecycle", "openssl", "packrat", + "renv", + "rlang", "rstudioapi", + "tools", "yaml" - ] + ], + "Hash": "c064d4993aedbf6c383041d1606aabeb" }, "rstudioapi": { "Package": "rstudioapi", - "Version": "0.14", + "Version": "0.15.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "690bd2acc42a9166ce34845884459320", - "Requirements": [] + "Hash": "5564500e25cffad9e22244ced1379887" }, "sass": { "Package": "sass", - "Version": "0.4.4", + "Version": "0.4.8", "Source": "Repository", "Repository": "CRAN", - "Hash": "c76cbac7ca04ce82d8c38e29729987a3", "Requirements": [ "R6", "fs", "htmltools", "rappdirs", "rlang" - ] + ], + "Hash": "168f9353c76d4c4b0a0bbf72e2c2d035" }, "shiny": { "Package": "shiny", - "Version": "1.7.4", + "Version": "1.8.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "c2eae3d8c670fa9dfa35a12066f4a1d5", "Requirements": [ + "R", "R6", "bslib", "cachem", @@ -716,222 +656,162 @@ "fastmap", "fontawesome", "glue", + "grDevices", "htmltools", "httpuv", "jsonlite", "later", "lifecycle", + "methods", "mime", "promises", "rlang", "sourcetools", + "tools", + "utils", "withr", "xtable" - ] + ], + "Hash": "3a1f41807d648a908e3c7f0334bf85e6" }, "sourcetools": { "Package": "sourcetools", - "Version": "0.1.7", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "947e4e02a79effa5d512473e10f41797", - "Requirements": [] - }, - "stringi": { - "Package": "stringi", - "Version": "1.7.12", + "Version": "0.1.7-1", "Source": "Repository", "Repository": "CRAN", - "Hash": "ca8bd84263c77310739d2cf64d84d7c9", - "Requirements": [] - }, - "stringr": { - "Package": "stringr", - "Version": "1.5.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "671a4d384ae9d32fc47a14e98bfa3dc8", "Requirements": [ - "cli", - "glue", - "lifecycle", - "magrittr", - "rlang", - "stringi", - "vctrs" - ] + "R" + ], + "Hash": "5f5a7629f956619d519205ec475fe647" }, "sys": { "Package": "sys", - "Version": "3.4.1", + "Version": "3.4.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "34c16f1ef796057bfa06d3f4ff818a5d", - "Requirements": [] + "Hash": "3a1be13d68d47a8cd0bfd74739ca1555" }, "testthat": { "Package": "testthat", - "Version": "3.1.6", + "Version": "3.2.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "7910146255835c66e9eb272fb215248d", "Requirements": [ + "R", "R6", "brio", "callr", "cli", "desc", "digest", - "ellipsis", "evaluate", "jsonlite", "lifecycle", "magrittr", + "methods", "pkgload", "praise", "processx", "ps", "rlang", + "utils", "waldo", "withr" - ] + ], + "Hash": "4767a686ebe986e6cb01d075b3f09729" }, "tibble": { "Package": "tibble", - "Version": "3.1.8", + "Version": "3.2.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "56b6934ef0f8c68225949a8672fe1a8f", "Requirements": [ + "R", "fansi", "lifecycle", "magrittr", + "methods", "pillar", "pkgconfig", "rlang", + "utils", "vctrs" - ] - }, - "usethis": { - "Package": "usethis", - "Version": "2.1.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "a67a22c201832b12c036cc059f1d137d", - "Requirements": [ - "cli", - "clipr", - "crayon", - "curl", - "desc", - "fs", - "gert", - "gh", - "glue", - "jsonlite", - "lifecycle", - "purrr", - "rappdirs", - "rlang", - "rprojroot", - "rstudioapi", - "whisker", - "withr", - "yaml" - ] + ], + "Hash": "a84e2cc86d07289b3b6f5069df7a004c" }, "utf8": { "Package": "utf8", - "Version": "1.2.2", + "Version": "1.2.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "c9c462b759a5cc844ae25b5942654d13", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "62b65c52671e6665f803ff02954446e9" }, "vctrs": { "Package": "vctrs", - "Version": "0.5.1", + "Version": "0.6.5", "Source": "Repository", "Repository": "CRAN", - "Hash": "970324f6572b4fd81db507b5d4062cb0", "Requirements": [ + "R", "cli", "glue", "lifecycle", "rlang" - ] + ], + "Hash": "c03fa420630029418f7e6da3667aac4a" }, "waldo": { "Package": "waldo", - "Version": "0.4.0", + "Version": "0.5.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "035fba89d0c86e2113120f93301b98ad", "Requirements": [ + "R", "cli", "diffobj", "fansi", "glue", + "methods", "rematch2", "rlang", "tibble" - ] - }, - "whisker": { - "Package": "whisker", - "Version": "0.4.1", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "c6abfa47a46d281a7d5159d0a8891e88", - "Requirements": [] + ], + "Hash": "c7d3fd6d29ab077cbac8f0e2751449e6" }, "withr": { "Package": "withr", - "Version": "2.5.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "c0e49a9760983e81e55cdd9be92e7182", - "Requirements": [] - }, - "xfun": { - "Package": "xfun", - "Version": "0.36", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "f5baec54606751aa53ac9c0e05848ed6", - "Requirements": [] - }, - "xml2": { - "Package": "xml2", - "Version": "1.3.3", + "Version": "2.5.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "40682ed6a969ea5abfd351eb67833adc", - "Requirements": [] + "Requirements": [ + "R", + "grDevices", + "graphics", + "stats" + ], + "Hash": "4b25e70111b7d644322e9513f403a272" }, "xtable": { "Package": "xtable", "Version": "1.8-4", "Source": "Repository", "Repository": "CRAN", - "Hash": "b8acdf8af494d9ec19ccb2481a9b11c2", - "Requirements": [] + "Requirements": [ + "R", + "stats", + "utils" + ], + "Hash": "b8acdf8af494d9ec19ccb2481a9b11c2" }, "yaml": { "Package": "yaml", - "Version": "2.3.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "9b570515751dcbae610f29885e025b41", - "Requirements": [] - }, - "zip": { - "Package": "zip", - "Version": "2.2.2", + "Version": "2.3.8", "Source": "Repository", "Repository": "CRAN", - "Hash": "c42bfcec3fa6a0cce17ce1f8bc684f88", - "Requirements": [] + "Hash": "29240487a071f535f5e5d5a323b7afbd" } } } diff --git a/renv/.gitignore b/renv/.gitignore index 63b9ec4..0ec0cbb 100644 --- a/renv/.gitignore +++ b/renv/.gitignore @@ -1,7 +1,7 @@ -sandbox/ -cellar/ library/ local/ +cellar/ lock/ python/ +sandbox/ staging/ diff --git a/renv/activate.R b/renv/activate.R index 019b5a6..cb5401f 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,11 +2,27 @@ local({ # the requested version of renv - version <- "0.16.0" + version <- "1.0.3" + 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({ @@ -60,21 +76,75 @@ local({ # load bootstrap tools `%||%` <- function(x, y) { - if (is.environment(x) || length(x)) x else 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() { @@ -83,28 +153,32 @@ local({ renv_bootstrap_repos <- function() { + # get CRAN repository + cran <- getOption("renv.repos.cran", "https://cloud.r-project.org") + # check for repos override repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) - if (!is.na(repos)) + if (!is.na(repos)) { + + # check for RSPM; if set, use a fallback repository for renv + rspm <- Sys.getenv("RSPM", unset = NA) + if (identical(rspm, repos)) + repos <- c(RSPM = rspm, CRAN = cran) + 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")) - # retrieve current repos repos <- getOption("repos") # ensure @CRAN@ entries are resolved - repos[repos == "@CRAN@"] <- getOption( - "renv.repos.cran", - "https://cloud.r-project.org" - ) + repos[repos == "@CRAN@"] <- cran # add in renv.bootstrap.repos if set default <- c(FALLBACK = "https://cloud.r-project.org") @@ -143,33 +217,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") } @@ -233,8 +308,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" @@ -251,13 +324,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 } @@ -314,8 +384,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( @@ -323,14 +391,11 @@ local({ condition = identity ) - if (identical(status, 0L)) { - message("OK") + if (identical(status, 0L)) return(destfile) - } } - message("FAILED") return(FALSE) } @@ -344,8 +409,7 @@ local({ return() # allow directories - info <- file.info(tarball, extra_cols = FALSE) - if (identical(info$isdir, TRUE)) { + if (dir.exists(tarball)) { name <- sprintf("renv_%s.tar.gz", version) tarball <- file.path(tarball, name) } @@ -354,7 +418,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) @@ -363,10 +427,7 @@ local({ } - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) - + catf("- Using local tarball '%s'.", tarball) tarball } @@ -393,8 +454,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) @@ -404,26 +463,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", @@ -431,19 +569,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) } @@ -653,34 +779,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-") @@ -700,6 +854,12 @@ local({ # warn if the version of renv loaded does not match renv_bootstrap_validate_version(version) + # execute renv load hooks, if any + hooks <- getHook("renv::autoload") + for (hook in hooks) + if (is.function(hook)) + tryCatch(hook(), error = warnify) + # load the project renv::load(project) @@ -839,14 +999,66 @@ 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) { + jlerr <- NULL + # if jsonlite is loaded, use that instead - if ("jsonlite" %in% loadedNamespaces()) - renv_json_read_jsonlite(file, text) + if ("jsonlite" %in% loadedNamespaces()) { + + json <- catch(renv_json_read_jsonlite(file, text)) + if (!inherits(json, "error")) + return(json) + + jlerr <- json + + } + + # otherwise, fall back to the default JSON reader + json <- catch(renv_json_read_default(file, text)) + if (!inherits(json, "error")) + return(json) + + # report an error + if (!is.null(jlerr)) + stop(jlerr) else - renv_json_read_default(file, text) + stop(json) } @@ -960,35 +1172,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() }) diff --git a/renv/settings.dcf b/renv/settings.dcf deleted file mode 100644 index 9d48169..0000000 --- a/renv/settings.dcf +++ /dev/null @@ -1,8 +0,0 @@ -external.libraries: -ignored.packages: -package.dependency.fields: Imports, Depends, LinkingTo -r.version: -snapshot.type: explicit -use.cache: TRUE -vcs.ignore.library: TRUE -vcs.ignore.local: TRUE diff --git a/renv/settings.json b/renv/settings.json new file mode 100644 index 0000000..74c1d4b --- /dev/null +++ b/renv/settings.json @@ -0,0 +1,19 @@ +{ + "bioconductor.version": null, + "external.libraries": [], + "ignored.packages": [], + "package.dependency.fields": [ + "Imports", + "Depends", + "LinkingTo" + ], + "ppm.enabled": null, + "ppm.ignored.urls": [], + "r.version": null, + "snapshot.type": "explicit", + "use.cache": true, + "vcs.ignore.cellar": true, + "vcs.ignore.library": true, + "vcs.ignore.local": true, + "vcs.manage.ignores": true +}