From e4c45acb728ea9152976ba33ae19c6b78e6e682f Mon Sep 17 00:00:00 2001 From: Amanyiraho Date: Wed, 14 Feb 2024 09:45:38 +0300 Subject: [PATCH 1/3] update packages --- renv.lock | 608 ++++++++------------------------------------- renv/activate.R | 434 +++++++++++++++++++++++--------- renv/settings.json | 19 ++ 3 files changed, 437 insertions(+), 624 deletions(-) create mode 100644 renv/settings.json diff --git a/renv.lock b/renv.lock index 8f61de4..14f98f7 100644 --- a/renv.lock +++ b/renv.lock @@ -1,6 +1,6 @@ { "R": { - "Version": "4.2.2", + "Version": "4.3.2", "Repositories": [ { "Name": "CRAN", @@ -14,383 +14,168 @@ "Version": "2.5.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "470851b6d5d0ac559e9d01bb352b4021", - "Requirements": [] + "Requirements": [ + "R" + ], + "Hash": "470851b6d5d0ac559e9d01bb352b4021" }, "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" - ] - }, - "base64enc": { - "Package": "base64enc", - "Version": "0.1-3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "543776ae6848fde2f48ff3816d0628bc", - "Requirements": [] - }, - "brio": { - "Package": "brio", - "Version": "1.1.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "976cf154dfb043c012d87cddd8bca363", - "Requirements": [] - }, - "bslib": { - "Package": "bslib", - "Version": "0.4.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "a7fbf03946ad741129dc81098722fca1", - "Requirements": [ - "base64enc", - "cachem", - "htmltools", - "jquerylib", - "jsonlite", - "memoise", - "mime", - "rlang", - "sass" - ] - }, - "cachem": { - "Package": "cachem", - "Version": "1.0.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "648c5b3d71e6a37e3043617489a0a0e9", "Requirements": [ - "fastmap", "rlang" - ] - }, - "callr": { - "Package": "callr", - "Version": "3.7.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "9b2191ede20fa29828139b9900922e51", - "Requirements": [ - "R6", - "processx" - ] + ], + "Hash": "d7421bb5dfeb2676b9e4a5a60c2fcfd2" }, "cli": { "Package": "cli", - "Version": "3.6.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "3177a5a16c243adc199ba33117bd9657", - "Requirements": [] - }, - "covr": { - "Package": "covr", - "Version": "3.6.1", + "Version": "3.6.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "a861cee34fbb4b107a73dd414ef56724", "Requirements": [ - "crayon", - "digest", - "httr", - "jsonlite", - "rex", - "withr", - "yaml" - ] - }, - "crayon": { - "Package": "crayon", - "Version": "1.5.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "e8a1e41acf02548751f45c718d55aa6a", - "Requirements": [] + "R", + "utils" + ], + "Hash": "1216ac65ac55ec0058a6f75d7ca0fd52" }, "curl": { "Package": "curl", - "Version": "4.3.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "0eb86baa62f06e8855258fa5a8048667", - "Requirements": [] - }, - "desc": { - "Package": "desc", - "Version": "1.4.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "6b9602c7ebbe87101a9c8edb6e8b6d21", - "Requirements": [ - "R6", - "cli", - "rprojroot" - ] - }, - "diffobj": { - "Package": "diffobj", - "Version": "0.3.5", + "Version": "5.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8", "Requirements": [ - "crayon" - ] - }, - "digest": { - "Package": "digest", - "Version": "0.6.31", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "8b708f296afd9ae69f450f9640be8990", - "Requirements": [] + "R" + ], + "Hash": "ce88d13c0b10fe88a37d9c59dba2d7f9" }, "dplyr": { "Package": "dplyr", - "Version": "1.0.10", + "Version": "1.1.4", "Source": "Repository", - "Repository": "CRAN", - "Hash": "539412282059f7f0c07295723d23f987", + "Repository": "RSPM", "Requirements": [ + "R", "R6", + "cli", "generics", "glue", "lifecycle", "magrittr", + "methods", "pillar", "rlang", "tibble", "tidyselect", + "utils", "vctrs" - ] - }, - "ellipsis": { - "Package": "ellipsis", - "Version": "0.3.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077", - "Requirements": [ - "rlang" - ] - }, - "evaluate": { - "Package": "evaluate", - "Version": "0.19", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "5aac3cd0a3ccb1a738941796b28c26fe", - "Requirements": [] + ], + "Hash": "fedd9d00c2944ff00a0e2696ccf048ec" }, "fansi": { "Package": "fansi", - "Version": "1.0.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "83a8afdbe71839506baa9f90eebad7ec", - "Requirements": [] - }, - "fastmap": { - "Package": "fastmap", - "Version": "1.1.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "77bd60a6157420d4ffa93b27cf6a58b8", - "Requirements": [] - }, - "fs": { - "Package": "fs", - "Version": "1.5.2", + "Version": "1.0.6", "Source": "Repository", "Repository": "CRAN", - "Hash": "7c89603d81793f0d5486d91ab1fc6f1d", - "Requirements": [] + "Requirements": [ + "R", + "grDevices", + "utils" + ], + "Hash": "962174cf2aeb5b9eea581522286a911f" }, "generics": { "Package": "generics", "Version": "0.1.3", "Source": "Repository", - "Repository": "CRAN", - "Hash": "15e9634c0fcd294799e9b2e929ed1b86", - "Requirements": [] + "Repository": "RSPM", + "Requirements": [ + "R", + "methods" + ], + "Hash": "15e9634c0fcd294799e9b2e929ed1b86" }, "glue": { "Package": "glue", - "Version": "1.6.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "4f2596dfb05dac67b9dc558e5c6fba2e", - "Requirements": [] - }, - "highr": { - "Package": "highr", - "Version": "0.10", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "06230136b2d2b9ba5805e1963fa6e890", - "Requirements": [ - "xfun" - ] - }, - "htmltools": { - "Package": "htmltools", - "Version": "0.5.4", + "Version": "1.7.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "9d27e99cc90bd701c0a7a63e5923f9b7", "Requirements": [ - "base64enc", - "digest", - "ellipsis", - "fastmap", - "rlang" - ] - }, - "httr": { - "Package": "httr", - "Version": "1.4.4", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "57557fac46471f0dbbf44705cc6a5c8c", - "Requirements": [ - "R6", - "curl", - "jsonlite", - "mime", - "openssl" - ] + "R", + "methods" + ], + "Hash": "e0b3a53876554bd45879e596cdb10a52" }, "httr2": { "Package": "httr2", - "Version": "0.2.2", + "Version": "1.0.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "5c09fe33064978ede54de42309c8b532", "Requirements": [ + "R", "R6", "cli", "curl", "glue", + "lifecycle", "magrittr", "openssl", "rappdirs", "rlang", + "vctrs", "withr" - ] - }, - "jquerylib": { - "Package": "jquerylib", - "Version": "0.1.4", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "5aab57a3bd297eee1c1d862735972182", - "Requirements": [ - "htmltools" - ] - }, - "jsonlite": { - "Package": "jsonlite", - "Version": "1.8.4", - "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" - ] - }, - "lazyeval": { - "Package": "lazyeval", - "Version": "0.2.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "d908914ae53b04d4c0c0fd72ecc35370", - "Requirements": [] + ], + "Hash": "e2b30f1fc039a0bab047dd52bb20ef71" }, "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": [] - }, - "memoise": { - "Package": "memoise", - "Version": "2.0.1", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c", "Requirements": [ - "cachem", - "rlang" - ] - }, - "mime": { - "Package": "mime", - "Version": "0.12", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "18e9c28c1d3ca1560ce30658b22ce104", - "Requirements": [] + "R" + ], + "Hash": "7ce2733a9826b3aeb1775d56fd305472" }, "openssl": { "Package": "openssl", - "Version": "2.0.5", + "Version": "2.1.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "b04c27110bf367b4daa93f34f3d58e75", "Requirements": [ "askpass" - ] + ], + "Hash": "2a0dc8c6adfb6f032e4d4af82d258ab5" }, "pillar": { "Package": "pillar", - "Version": "1.8.1", + "Version": "1.9.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "f2316df30902c81729ae9de95ad5a608", "Requirements": [ "cli", "fansi", @@ -398,306 +183,129 @@ "lifecycle", "rlang", "utf8", + "utils", "vctrs" - ] + ], + "Hash": "15da5a8412f317beeee6175fbc76f4bb" }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "01f28d4278f15c76cddbea05899c5d6f", - "Requirements": [] - }, - "pkgload": { - "Package": "pkgload", - "Version": "1.3.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "6b0c222c5071efe0f3baf3dae9aa40e2", - "Requirements": [ - "cli", - "crayon", - "desc", - "fs", - "glue", - "rlang", - "rprojroot", - "withr" - ] - }, - "praise": { - "Package": "praise", - "Version": "1.0.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "a555924add98c99d2f411e37e7d25e9f", - "Requirements": [] - }, - "processx": { - "Package": "processx", - "Version": "3.8.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "a33ee2d9bf07564efb888ad98410da84", "Requirements": [ - "R6", - "ps" - ] - }, - "ps": { - "Package": "ps", - "Version": "1.7.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "68dd03d98a5efd1eb3012436de45ba83", - "Requirements": [] + "utils" + ], + "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, "rappdirs": { "Package": "rappdirs", "Version": "0.3.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "5e3c5dc0b071b21fa128676560dbe94d", - "Requirements": [] - }, - "rematch2": { - "Package": "rematch2", - "Version": "2.1.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "76c9e04c712a05848ae7a23d2f170a40", "Requirements": [ - "tibble" - ] + "R" + ], + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" }, "renv": { "Package": "renv", - "Version": "0.16.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "c9e8442ab69bc21c9697ecf856c1e6c7", - "Requirements": [] - }, - "rex": { - "Package": "rex", - "Version": "1.2.1", + "Version": "1.0.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "ae34cd56890607370665bee5bd17812f", "Requirements": [ - "lazyeval" - ] + "utils" + ], + "Hash": "41b847654f567341725473431dd0d5ab" }, "rlang": { "Package": "rlang", - "Version": "1.0.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "4ed1f8336c8d52c3e750adcdc57228a7", - "Requirements": [] - }, - "rmarkdown": { - "Package": "rmarkdown", - "Version": "2.19", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "4e29299e1f4c7eabb0b8365b338adf3c", - "Requirements": [ - "bslib", - "evaluate", - "htmltools", - "jquerylib", - "jsonlite", - "knitr", - "stringr", - "tinytex", - "xfun", - "yaml" - ] - }, - "rprojroot": { - "Package": "rprojroot", - "Version": "2.0.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "1de7ab598047a87bba48434ba35d497d", - "Requirements": [] - }, - "sass": { - "Package": "sass", - "Version": "0.4.4", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "c76cbac7ca04ce82d8c38e29729987a3", - "Requirements": [ - "R6", - "fs", - "htmltools", - "rappdirs", - "rlang" - ] - }, - "stringi": { - "Package": "stringi", - "Version": "1.7.8", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "a68b980681bcbc84c7a67003fa796bfb", - "Requirements": [] - }, - "stringr": { - "Package": "stringr", - "Version": "1.5.0", + "Version": "1.1.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "671a4d384ae9d32fc47a14e98bfa3dc8", "Requirements": [ - "cli", - "glue", - "lifecycle", - "magrittr", - "rlang", - "stringi", - "vctrs" - ] + "R", + "utils" + ], + "Hash": "42548638fae05fd9a9b5f3f437fbbbe2" }, "sys": { "Package": "sys", - "Version": "3.4.1", + "Version": "3.4.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "34c16f1ef796057bfa06d3f4ff818a5d", - "Requirements": [] - }, - "testthat": { - "Package": "testthat", - "Version": "3.1.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "7910146255835c66e9eb272fb215248d", - "Requirements": [ - "R6", - "brio", - "callr", - "cli", - "desc", - "digest", - "ellipsis", - "evaluate", - "jsonlite", - "lifecycle", - "magrittr", - "pkgload", - "praise", - "processx", - "ps", - "rlang", - "waldo", - "withr" - ] + "Hash": "3a1be13d68d47a8cd0bfd74739ca1555" }, "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" - ] + ], + "Hash": "a84e2cc86d07289b3b6f5069df7a004c" }, "tidyselect": { "Package": "tidyselect", "Version": "1.2.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "79540e5fcd9e0435af547d885f184fd5", + "Repository": "RSPM", "Requirements": [ + "R", "cli", "glue", "lifecycle", "rlang", "vctrs", "withr" - ] - }, - "tinytex": { - "Package": "tinytex", - "Version": "0.43", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "facc02f3d63ed7dd765513c004c394ce", - "Requirements": [ - "xfun" - ] + ], + "Hash": "79540e5fcd9e0435af547d885f184fd5" }, "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" - ] - }, - "waldo": { - "Package": "waldo", - "Version": "0.4.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "035fba89d0c86e2113120f93301b98ad", - "Requirements": [ - "cli", - "diffobj", - "fansi", - "glue", - "rematch2", - "rlang", - "tibble" - ] + ], + "Hash": "c03fa420630029418f7e6da3667aac4a" }, "withr": { "Package": "withr", - "Version": "2.5.0", + "Version": "3.0.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "c0e49a9760983e81e55cdd9be92e7182", - "Requirements": [] - }, - "xfun": { - "Package": "xfun", - "Version": "0.36", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "f5baec54606751aa53ac9c0e05848ed6", - "Requirements": [] - }, - "yaml": { - "Package": "yaml", - "Version": "2.3.6", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "9b570515751dcbae610f29885e025b41", - "Requirements": [] + "Requirements": [ + "R", + "grDevices", + "graphics" + ], + "Hash": "d31b6c62c10dcf11ec530ca6b0dd5d35" } } } 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.json b/renv/settings.json new file mode 100644 index 0000000..b8adabd --- /dev/null +++ b/renv/settings.json @@ -0,0 +1,19 @@ +{ + "bioconductor.version": [], + "external.libraries": [], + "ignored.packages": [], + "package.dependency.fields": [ + "Imports", + "Depends", + "LinkingTo" + ], + "ppm.enabled": null, + "ppm.ignored.urls": [], + "r.version": [], + "snapshot.type": "explicit", + "use.cache": true, + "vcs.ignore.cellar": true, + "vcs.ignore.library": true, + "vcs.ignore.local": true, + "vcs.manage.ignores": true +} From 9ed249c6e2c712217f28a4c535dad76e323a71a7 Mon Sep 17 00:00:00 2001 From: Amanyiraho Date: Wed, 14 Feb 2024 10:34:40 +0300 Subject: [PATCH 2/3] update readme with PAT --- NEWS.md | 11 ++++++++--- README.Rmd | 2 ++ README.md | 13 +++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index d378dfe..9971e2a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ +# dhis2r 0.2.0 + +## Improvements + +* Add authentication via personal access token @Brar + # dhis2r 0.1.1 -Updated tests for analytics to be flexible to cover unavailable data on a DHIS2 instance -# dhis2r 0.1.0 +* Fix R CMD check failures on CRAN -* Added a `NEWS.md` file to track changes to the package. +* Added a NEWS.md file to track changes to the package. diff --git a/README.Rmd b/README.Rmd index 26c1668..ded6155 100644 --- a/README.Rmd +++ b/README.Rmd @@ -75,7 +75,9 @@ Alternatively you can generate a [personal access token](https://docs.dhis2.org/ ``` r library(dhis2r) + # Replace the value of api_token with the token you have generated + dhis2_play_connection <- Dhis2r$new(base_url = "https://play.dhis2.org/", api_token = "d2pat_5xVA12xyUbWNedQxy4ohH77WlxRGVvZZ1151814092") ``` diff --git a/README.md b/README.md index fae5196..45a8fca 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,19 @@ dhis2_play_connection <- Dhis2r$new(base_url = "https://play.dhis2.org/", api_version_position = "before") ``` +Alternatively you can generate a [personal access +token](https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/introduction.html#webapi_pat_authentication) +and use that to connect. + +``` r +library(dhis2r) + +# Replace the value of api_token with the token you have generated + +dhis2_play_connection <- Dhis2r$new(base_url = "https://play.dhis2.org/", + api_token = "d2pat_5xVA12xyUbWNedQxy4ohH77WlxRGVvZZ1151814092") +``` + `Dhis2r$new()` returns a `Dhis2r` R6 class which represents a DHIS2 connection and can be used to query the DHIS2 instance From 9d1db60dfb5d69073d3925783ba54ccc268408a8 Mon Sep 17 00:00:00 2001 From: Amanyiraho Date: Wed, 14 Feb 2024 12:47:46 +0300 Subject: [PATCH 3/3] add any analytic function --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/connect.R | 49 +++++++++++++++++++++++++++++++++++++++++--- man/Dhis2r.Rd | 30 ++++++++++++++++++++++++--- vignettes/dhis2r.Rmd | 1 + 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5602bbd..9d6fa65 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,5 +23,5 @@ Suggests: Depends: R (>= 4.1.0) Encoding: UTF-8 VignetteBuilder: knitr -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 LazyData: true diff --git a/NEWS.md b/NEWS.md index 9971e2a..ae0268f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ * Add authentication via personal access token @Brar +* Added `get_any_analytic()` to cater for long DHIS2 favorites + # dhis2r 0.1.1 * Fix R CMD check failures on CRAN diff --git a/R/connect.R b/R/connect.R index 70ec732..0f19617 100644 --- a/R/connect.R +++ b/R/connect.R @@ -112,7 +112,7 @@ Dhis2r <- R6::R6Class( } self$request_sent <- self$request_sent |> - req_url_query(paging = "false") |> + # req_url_query(paging = "false") |> req_headers("Accept" = "application/json") |> httr2::req_user_agent("dhis2r (http://www.amanyiraho.com/dhis2r/") |> httr2::req_retry(max_tries = 5) @@ -233,7 +233,7 @@ Dhis2r <- R6::R6Class( #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #' @description Get all possible analytics resources from a DHIS2 instance i.e #' - #' @return A vector of all possible fields for a specific metadata + #' @return A data frame of the analytics resource #' #' @param analytic vector of ID of specific analytic(s) from a DHIS2 instance #' @param org_unit vector of ID of specific organisation unit(s) from a DHIS2 instance @@ -284,7 +284,50 @@ Dhis2r <- R6::R6Class( - } + }, + + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + #' @description Get all any analytics resource from a DHIS2 instance to cater for long DHIS2 favorites + #' + #' @return A data frame of the analytics resource + #' + #' @param endpoint_url string part of Analytic(s) from a DHIS2 instance api endpoint starting from `analytics.json?dimension=dx%3...` + #' + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + get_any_analytic = function(endpoint_url) { + # Check for internet + check_internet() + args <- list(endpoint_url = endpoint_url) + #Check that at least one argument is not null + + attempt::stop_if_any(args, is.null,"You need to specify all arguements") + attempt::stop_if_none(args, is.character, "All arguements should be type character") + + + response_object <- self$request_sent |> + req_url_path_append(endpoint_url) |> + req_perform() + + print(response_object$url) + + + response_data <- response_object |> + resp_body_json(simplifyVector = TRUE, flatten = TRUE) + + if(length(response_data$rows) == 0){ + + as.data.frame(response_data$rows) + + }else{ + as.data.frame(response_data$rows) |> + tibble::as_tibble() + } + + + + } + ) diff --git a/man/Dhis2r.Rd b/man/Dhis2r.Rd index 33fa13b..7d73b16 100644 --- a/man/Dhis2r.Rd +++ b/man/Dhis2r.Rd @@ -62,6 +62,7 @@ period = "LAST_12_MONTHS", \item \href{#method-Dhis2r-get_metadata}{\code{Dhis2r$get_metadata()}} \item \href{#method-Dhis2r-get_metadata_fields}{\code{Dhis2r$get_metadata_fields()}} \item \href{#method-Dhis2r-get_analytics}{\code{Dhis2r$get_analytics()}} +\item \href{#method-Dhis2r-get_any_analytic}{\code{Dhis2r$get_any_analytic()}} \item \href{#method-Dhis2r-clone}{\code{Dhis2r$clone()}} } } @@ -73,8 +74,9 @@ Create a connection to a DHIS2 instance using basic authentication \subsection{Usage}{ \if{html}{\out{
}}\preformatted{Dhis2r$new( base_url, - username, - password, + username = NULL, + password = NULL, + api_token = NULL, api_version = NULL, api_version_position = c("after", "before") )}\if{html}{\out{
}} @@ -89,6 +91,8 @@ Create a connection to a DHIS2 instance using basic authentication \item{\code{password}}{Registered password e.g "district"} +\item{\code{api_token}}{Personal Access Token (PAT) to use instead of username and password} + \item{\code{api_version}}{The api version e.g "33"} \item{\code{api_version_position}}{position where the api_version is after or before in web API url i.e /api/} @@ -183,7 +187,27 @@ Get all possible analytics resources from a DHIS2 instance i.e \if{html}{\out{}} } \subsection{Returns}{ -A vector of all possible fields for a specific metadata +A data frame of the analytics resource +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Dhis2r-get_any_analytic}{}}} +\subsection{Method \code{get_any_analytic()}}{ +Get all any analytics resource from a DHIS2 instance to cater for long DHIS2 favorites +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dhis2r$get_any_analytic(endpoint_url)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{endpoint_url}}{string part of Analytic(s) from a DHIS2 instance api endpoint starting from `analytics.json?dimension=dx%3...`} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +A data frame of the analytics resource } } \if{html}{\out{
}} diff --git a/vignettes/dhis2r.Rmd b/vignettes/dhis2r.Rmd index 087409b..27940d9 100644 --- a/vignettes/dhis2r.Rmd +++ b/vignettes/dhis2r.Rmd @@ -116,6 +116,7 @@ dhis2_play_connection$get_metadata(endpoint = "periodTypes", fields = ":all") ``` indicators + ```{r} dhis2_play_connection$get_metadata(endpoint = "indicators") ```