diff --git a/.Rbuildignore b/.Rbuildignore index 74e08d25f95aeff6cb535677b434a1b7947c1825..525826344e56d6b28ad4457aab7de0e14293be32 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -29,3 +29,4 @@ tests/testhat/\~import_coe20092015\.csv ^public ^ci ^Scripts +^cache \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd1bf1b6ea961cd9b5827d1b03bbe25ecbf957f5..ba5263ddfa6a460ebcd55dd85a932633803a12ff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,12 +35,16 @@ variables: REPO_NAME: "{repo_name}" R_LIBS: "ci/lib" R_LIBS_USER: "ci/lib" + RENV_PATHS_CACHE: "cache" + RENV_PATHS_LIBRARY: "renv/library" #key for caching per branch cache: key: $CI_COMMIT_REF_SLUG paths: + - ${RENV_PATHS_CACHE} + - ${RENV_PATHS_LIBRARY} - ${R_LIBS_USER} @@ -63,31 +67,16 @@ buildpackage: only: - main - master - - 0.6.0.7 + - 0.6.0.7 needs: [] script: - mkdir -p $R_LIBS_USER + - mkdir -p $RENV_PATHS_CACHE - mkdir -p public - # from https://www.algorist.co.uk/post/building-a-ci-pipeline-for-r-packages-in-gitlab/ - - echo 'R_LIBS=$R_LIBS_USER' > .Renviron - - echo 'R_LIBS_USER=$R_LIBS_USER' >> .Renviron - - echo 'R_LIBS_SITE=$R_LIBS_USER' >> .Renviron - #- echo 'PGPASSWORD=$POSTGRES_PASSWORD' >> .Renviron # I need to pass the variable to use later in test - # d --deps dependencies, r - - apt-get update -y - - apt-get install -y libpq-dev - - apt-get install -y r-cran-rodbc - #- install2.r --deps TRUE --libloc "ci/lib" --repos "https://pbil.univ-lyon1.fr/CRAN/" --error --skipinstalled RODBC + - Rscript -e 'source("renv/activate.R")' - Rscript -e 'if(!requireNamespace("pak", quietly = TRUE)) {install.packages("pak")}' - - Rscript -e 'pak::pkg_install(pkg = c("stacomirtools", "RPostgres", "xtable", "magrittr", "intervals", "RColorBrewer"), lib = "'$R_LIBS_USER'", upgrade = TRUE)' - # these are for code coverage - - Rscript -e 'pak::pkg_install(pkg = c("covr", "DT"), lib = "'$R_LIBS_USER'", upgrade = TRUE)' - - Rscript -e 'pak::pkg_install(pkg = c("reshape2", "graphics", "utils", "stats", "lattice", "grDevices", "Hmisc", "lubridate", "mgcv", "withr", "XML"), lib = "'$R_LIBS_USER'", upgrade = TRUE)' - - rm -rf /tmp/downloaded_packages - #- r -e 'install.packages(c("stacomirtools","RPostgres","xtable","magrittr","intervals","RColorBrewer"), lib= "ci/lib", dependencies = TRUE, repos =)'> public/logr - #- r -e 'install.packages(c(), lib= "ci/lib", repos= "https://pbil.univ-lyon1.fr/CRAN/", dependencies = TRUE)'>> public/logr - #- r -e 'install.packages(c("xml2"), repos= "https://pbil.univ-lyon1.fr/CRAN/", lib= "ci/lib", dependencies = TRUE)'>> public/logr # this one is for test with JUNIT reporter - #- if [[ $CI_DEFAULT_BRANCH == "master" || $CI_DEFAULT_BRANCH = "main" || $CI_DEFAULT_BRANCH = "0.6.0.7"]]; then echo "OK - default branch is master or main or 0.6.0.7"; else echo "default branch is not master or main or 0.6.0.7, please add yours ($CI_0.6.0.7_BRANCH) where needed, as well as in the present line of code" ; exit 1; fi + - Rscript -e 'pak::pkg_install(pkg = c("rcmdcheck", "renv"), upgrade = FALSE)' + - Rscript -e 'renv::restore()' - r -e 'devtools::build(binary = TRUE, path="public", vignettes=TRUE, manual=TRUE)' - r -e 'devtools::build(binary = FALSE, path="public", vignettes=TRUE)' artifacts: @@ -95,8 +84,6 @@ buildpackage: paths: - public - ${R_LIBS_USER} - - "$(ls -rt *.zip |tail -1)" - - "$(ls -rt *.tar.gz |tail -1)" @@ -146,11 +133,27 @@ checkerrors: - 0.6.0.7 script: - mkdir -p public/check - - echo 'R_LIBS=$R_LIBS_USER' > .Renviron - - echo 'R_LIBS_USER=$R_LIBS_USER' >> .Renviron - - echo 'R_LIBS_SITE=$R_LIBS_USER' >> .Renviron - - r -e 'devtools::load_all();devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check")' - #- check.r --repo "https://pbil.univ-lyon1.fr/CRAN/" --install-deps --library "ci/lib" + - r -e 'devtools::load_all();devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check")' + artifacts: + when: always + paths: + - public/check + expire_in: 30 days + +checkerrors_update: + before_script: + - apt-get update + - apt-get install -y qpdf + stage: check + needs: ["buildpackage"] + only: + - main + - master + - 0.6.0.7 + script: + - mkdir -p public/check + - Rscript -e 'renv::update()' + - r -e 'devtools::load_all();devtools::check(document = FALSE, args = "--no-tests", check_dir="public/check")' artifacts: when: always paths: @@ -164,13 +167,10 @@ unittests: only: - main - master - - 0.6.0.7 + - 0.6.0.7 script: - export PGPASSWORD=$POSTGRES_PASSWORD - - echo 'R_LIBS=$R_LIBS_USER' > .Renviron - - echo 'R_LIBS_USER=$R_LIBS_USER' >> .Renviron - - echo 'R_LIBS_SITE=$R_LIBS_USER' >> .Renviron - echo 'PGPASSWORD=$POSTGRES_PASSWORD' >> .Renviron - r -e 'devtools::load_all();options(stacomiR.dbname = "bd_contmig_nat",stacomiR.host ="db", stacomiR.port = "5432", stacomiR.user = "postgres", stacomiR.password = "postgres"); test <- capture.output(devtools::test(reporter="junit")) ; XML::saveXML(XML::xmlParse(test[grep("?xml version",test):length(test)]), file="public/test.xml")' - r -e 'a<-1' @@ -197,13 +197,11 @@ codecov: - master - 0.6.0.7 script: - - echo 'R_LIBS=$R_LIBS_USER' > .Renviron - - echo 'R_LIBS_USER=$R_LIBS_USER' >> .Renviron - - echo 'R_LIBS_SITE=$R_LIBS_USER' >> .Renviron - #- echo 'PGPASSWORD=$POSTGRES_PASSWORD' >> .Renviron + # these are for code coverage + - Rscript -e 'pak::pkg_install(pkg = c("covr", "DT"), upgrade = FALSE)' - r -e 'Sys.setenv("NOT_CRAN"= "true"); devtools::load_all(); options(stacomiR.dbname = "bd_contmig_nat",stacomiR.host ="db", stacomiR.port = "5432", stacomiR.user = "postgres", stacomiR.password = "postgres");co <- covr::package_coverage(type="all", quiet=FALSE, clean=FALSE);print(co);covr:::print.coverage(co);covr::report(co, file.path("dev/codecoverage_report", paste0("stacomiR-report.html")))' # the following should be used when pages is set - #- r -e 'covr::gitlab(file = "public/coverage.html", type = c("all"), quiet = FALSE)' + - r -e 'covr::gitlab(file = "public/coverage.html", type = c("all"), quiet = FALSE)' #A line like Code coverage: 67.89% of lines covered would match. coverage: '/Coverage: \d+\.\d+/' artifacts: diff --git a/renv.lock b/renv.lock index 53554c036ee8a2cc5fce8e772bb80431d9264797..b518bbca9b5fa3d4cdfdde71604fe0170cb679ac 100644 --- a/renv.lock +++ b/renv.lock @@ -143,24 +143,24 @@ }, "Rcpp": { "Package": "Rcpp", - "Version": "1.0.12", + "Version": "1.0.13", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods", "utils" ], - "Hash": "5ea2700d21e038ace58269ecdbeb9ec0" + "Hash": "f27411eb6d9c3dada5edd444b8416675" }, "backports": { "Package": "backports", - "Version": "1.4.1", + "Version": "1.5.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "c39fbec8a30d23e721980b8afb31984c" + "Hash": "e1e1b9d75c37401117b636b7ae50827a" }, "base64enc": { "Package": "base64enc", @@ -210,7 +210,7 @@ }, "bslib": { "Package": "bslib", - "Version": "0.7.0", + "Version": "0.8.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -228,7 +228,7 @@ "rlang", "sass" ], - "Hash": "8644cc53f43828f19133548195d7e59e" + "Hash": "b299c6741ca9746fb227debcb0f9fb6c" }, "cachem": { "Package": "cachem", @@ -243,7 +243,7 @@ }, "checkmate": { "Package": "checkmate", - "Version": "2.3.1", + "Version": "2.3.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -251,18 +251,18 @@ "backports", "utils" ], - "Hash": "c01cab1cb0f9125211a6fc99d540e315" + "Hash": "0e14e01ce07e7c88fd25de6d4260d26b" }, "cli": { "Package": "cli", - "Version": "3.6.2", + "Version": "3.6.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "1216ac65ac55ec0058a6f75d7ca0fd52" + "Hash": "b21916dd77a27642b447374a5d30ecf3" }, "cluster": { "Package": "cluster", @@ -280,7 +280,7 @@ }, "colorspace": { "Package": "colorspace", - "Version": "2.1-0", + "Version": "2.1-1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -290,39 +290,39 @@ "methods", "stats" ], - "Hash": "f20c47fd52fae58b4e377c37bb8c335b" + "Hash": "d954cb1c57e8d8b756165d7ba18aa55a" }, "cpp11": { "Package": "cpp11", - "Version": "0.4.7", + "Version": "0.5.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "5a295d7d963cc5035284dcdbaf334f4e" + "Hash": "91570bba75d0c9d3f1040c835cee8fba" }, "data.table": { "Package": "data.table", - "Version": "1.15.4", + "Version": "1.16.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "8ee9ac56ef633d0c7cab8b2ca87d683e" + "Hash": "fb24e05d4a91d8b1c7ff8e284bde834a" }, "digest": { "Package": "digest", - "Version": "0.6.35", + "Version": "0.6.37", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "698ece7ba5a4fa4559e3d537e7ec3d31" + "Hash": "33698c4b3127fc9f506654607fb73676" }, "dplyr": { "Package": "dplyr", @@ -349,14 +349,13 @@ }, "evaluate": { "Package": "evaluate", - "Version": "0.23", + "Version": "1.0.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ - "R", - "methods" + "R" ], - "Hash": "daf4a1246be12c1fa8c7705a0935c1a0" + "Hash": "6b567375113ceb7d9f800de4dd42218e" }, "fansi": { "Package": "fansi", @@ -398,7 +397,7 @@ }, "foreign": { "Package": "foreign", - "Version": "0.8-86", + "Version": "0.8-87", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -407,7 +406,7 @@ "stats", "utils" ], - "Hash": "550170303dbb19d07b2bcc288068e7dc" + "Hash": "81fc09bdeab0077a73927ed1243404b6" }, "fs": { "Package": "fs", @@ -458,14 +457,14 @@ }, "glue": { "Package": "glue", - "Version": "1.7.0", + "Version": "1.8.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "e0b3a53876554bd45879e596cdb10a52" + "Hash": "5899f1eaa825580172bb56c08266f37c" }, "gridExtra": { "Package": "gridExtra", @@ -523,7 +522,7 @@ }, "htmlTable": { "Package": "htmlTable", - "Version": "2.4.2", + "Version": "2.4.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -537,7 +536,7 @@ "rstudioapi", "stringr" ], - "Hash": "0164d8cade33fac2190703da7e6e3241" + "Hash": "ca027d8771f2c039aed82f00a81e725b" }, "htmltools": { "Package": "htmltools", @@ -606,13 +605,13 @@ }, "jsonlite": { "Package": "jsonlite", - "Version": "1.8.8", + "Version": "1.8.9", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods" ], - "Hash": "e1b9c55281c5adc4dd113652d9e26768" + "Hash": "4e993b65c2c3ffbffce7bb3e2c6f832b" }, "knitr": { "Package": "knitr", @@ -754,7 +753,7 @@ }, "nlme": { "Package": "nlme", - "Version": "3.1-165", + "Version": "3.1-166", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -764,7 +763,7 @@ "stats", "utils" ], - "Hash": "2769a88be217841b1f33ed469675c3cc" + "Hash": "ccbb8846be320b627e6aa2b4616a2ded" }, "nnet": { "Package": "nnet", @@ -850,13 +849,13 @@ }, "renv": { "Package": "renv", - "Version": "1.0.7", + "Version": "1.0.9", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "utils" ], - "Hash": "397b7b2a265bc5a7a06852524dabae20" + "Hash": "ef233f0e9064fc88c898b340c9add5c2" }, "reshape2": { "Package": "reshape2", @@ -1053,13 +1052,13 @@ }, "tinytex": { "Package": "tinytex", - "Version": "0.51", + "Version": "0.53", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "xfun" ], - "Hash": "d44e2fcd2e4e076f0aac540208559d1d" + "Hash": "9db859e8aabbb474293dde3097839420" }, "utf8": { "Package": "utf8", @@ -1122,15 +1121,16 @@ }, "xfun": { "Package": "xfun", - "Version": "0.44", + "Version": "0.47", "Source": "Repository", "Repository": "CRAN", "Requirements": [ + "R", "grDevices", "stats", "tools" ], - "Hash": "317a0538d32f4a009658bcedb7923f4b" + "Hash": "36ab21660e2d095fef0d83f689e0477c" }, "xtable": { "Package": "xtable", @@ -1146,10 +1146,10 @@ }, "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 d13f9932a16a92986a514d8cb439662d85db3add..c360bf2962d9071ffee0bcb70101316cef71074b 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,7 +2,7 @@ local({ # the requested version of renv - version <- "1.0.7" + version <- "1.0.9" attr(version, "sha") <- NULL # the project directory @@ -98,6 +98,66 @@ local({ unloadNamespace("renv") # load bootstrap tools + ansify <- function(text) { + if (renv_ansify_enabled()) + renv_ansify_enhanced(text) + else + renv_ansify_default(text) + } + + renv_ansify_enabled <- function() { + + override <- Sys.getenv("RENV_ANSIFY_ENABLED", unset = NA) + if (!is.na(override)) + return(as.logical(override)) + + pane <- Sys.getenv("RSTUDIO_CHILD_PROCESS_PANE", unset = NA) + if (identical(pane, "build")) + return(FALSE) + + testthat <- Sys.getenv("TESTTHAT", unset = "false") + if (tolower(testthat) %in% "true") + return(FALSE) + + iderun <- Sys.getenv("R_CLI_HAS_HYPERLINK_IDE_RUN", unset = "false") + if (tolower(iderun) %in% "false") + return(FALSE) + + TRUE + + } + + renv_ansify_default <- function(text) { + text + } + + renv_ansify_enhanced <- function(text) { + + # R help links + pattern <- "`\\?(renv::(?:[^`])+)`" + replacement <- "`\033]8;;ide:help:\\1\a?\\1\033]8;;\a`" + text <- gsub(pattern, replacement, text, perl = TRUE) + + # runnable code + pattern <- "`(renv::(?:[^`])+)`" + replacement <- "`\033]8;;ide:run:\\1\a\\1\033]8;;\a`" + text <- gsub(pattern, replacement, text, perl = TRUE) + + # return ansified text + text + + } + + renv_ansify_init <- function() { + + envir <- renv_envir_self() + if (renv_ansify_enabled()) + assign("ansify", renv_ansify_enhanced, envir = envir) + else + assign("ansify", renv_ansify_default, envir = envir) + + } + `%||%` <- function(x, y) { if (is.null(x)) y else x } @@ -142,7 +202,10 @@ local({ # compute common indent indent <- regexpr("[^[:space:]]", lines) common <- min(setdiff(indent, -1L)) - leave - paste(substring(lines, common), collapse = "\n") + text <- paste(substring(lines, common), collapse = "\n") + + # substitute in ANSI links for executable renv code + ansify(text) } @@ -306,7 +369,11 @@ local({ ) if ("headers" %in% names(formals(utils::download.file))) - args$headers <- renv_bootstrap_download_custom_headers(url) + { + headers <- renv_bootstrap_download_custom_headers(url) + if (length(headers) && is.character(headers)) + args$headers <- headers + } do.call(utils::download.file, args) @@ -385,10 +452,22 @@ local({ for (type in types) { for (repos in renv_bootstrap_repos()) { + # build arguments for utils::available.packages() call + args <- list(type = type, repos = repos) + + # add custom headers if available -- note that + # utils::available.packages() will pass this to download.file() + if ("headers" %in% names(formals(utils::download.file))) + { + headers <- renv_bootstrap_download_custom_headers(url) + if (length(headers) && is.character(headers)) + args$headers <- headers + } + # retrieve package database db <- tryCatch( as.data.frame( - utils::available.packages(type = type, repos = repos), + do.call(utils::available.packages, args), stringsAsFactors = FALSE ), error = identity @@ -470,6 +549,14 @@ local({ } + renv_bootstrap_github_token <- function() { + for (envvar in c("GITHUB_TOKEN", "GITHUB_PAT", "GH_TOKEN")) { + envval <- Sys.getenv(envvar, unset = NA) + if (!is.na(envval)) + return(envval) + } + } + renv_bootstrap_download_github <- function(version) { enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE") @@ -477,16 +564,16 @@ local({ return(FALSE) # prepare download options - pat <- Sys.getenv("GITHUB_PAT") - if (nzchar(Sys.which("curl")) && nzchar(pat)) { + token <- renv_bootstrap_github_token() + if (nzchar(Sys.which("curl")) && nzchar(token)) { fmt <- "--location --fail --header \"Authorization: token %s\"" - extra <- sprintf(fmt, pat) + extra <- sprintf(fmt, token) saved <- options("download.file.method", "download.file.extra") options(download.file.method = "curl", download.file.extra = extra) on.exit(do.call(base::options, saved), add = TRUE) - } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { + } else if (nzchar(Sys.which("wget")) && nzchar(token)) { fmt <- "--header=\"Authorization: token %s\"" - extra <- sprintf(fmt, pat) + extra <- sprintf(fmt, token) saved <- options("download.file.method", "download.file.extra") options(download.file.method = "wget", download.file.extra = extra) on.exit(do.call(base::options, saved), add = TRUE)