From 0f3d68fcb958e511cbb7910c2ca26b27d3b5d364 Mon Sep 17 00:00:00 2001 From: Martijn Schuemie Date: Sun, 22 Oct 2023 22:57:48 +0200 Subject: [PATCH] Simplying dependencies of Shiny app Co-authored-by: Gowtham Rao Co-authored-by: Admin_mschuemi --- CohortExplorer.Rproj | 1 - inst/shiny/R/private.R | 18 ++ inst/shiny/renv.lock | 239 +++++++++------------ inst/shiny/renv/activate.R | 388 +++++++++++++++++++++++----------- inst/shiny/renv/settings.dcf | 10 - inst/shiny/renv/settings.json | 17 -- inst/shiny/server.R | 4 +- inst/shiny/ui.R | 4 +- 8 files changed, 390 insertions(+), 291 deletions(-) delete mode 100644 inst/shiny/renv/settings.dcf delete mode 100644 inst/shiny/renv/settings.json diff --git a/CohortExplorer.Rproj b/CohortExplorer.Rproj index eaa6b81..5a4617f 100644 --- a/CohortExplorer.Rproj +++ b/CohortExplorer.Rproj @@ -13,6 +13,5 @@ RnwWeave: Sweave LaTeX: pdfLaTeX BuildType: Package -PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace diff --git a/inst/shiny/R/private.R b/inst/shiny/R/private.R index 4c9ad67..b72de37 100644 --- a/inst/shiny/R/private.R +++ b/inst/shiny/R/private.R @@ -30,3 +30,21 @@ readData <- function(databaseId, return(NULL) } } + + +snakeCaseToCamelCase <- function(string) { + string <- tolower(string) + for (letter in letters) { + string <- gsub(paste("_", letter, sep = ""), toupper(letter), string) + } + string <- gsub("_([0-9])", "\\1", string) + return(string) +} + +camelCaseToTitleCase <- function(string) { + string <- gsub("([A-Z])", " \\1", string) + string <- gsub("([a-z])([0-9])", "\\1 \\2", string) + substr(string, 1, 1) <- toupper(substr(string, 1, 1)) + return(string) +} + diff --git a/inst/shiny/renv.lock b/inst/shiny/renv.lock index ab97b24..c1072c8 100644 --- a/inst/shiny/renv.lock +++ b/inst/shiny/renv.lock @@ -1,10 +1,10 @@ { "R": { - "Version": "4.2.1", + "Version": "4.2.3", "Repositories": [ { "Name": "CRAN", - "URL": "https://cran.rstudio.com" + "URL": "https://cloud.r-project.org" } ] }, @@ -18,7 +18,7 @@ }, "MASS": { "Package": "MASS", - "Version": "7.3-57", + "Version": "7.3-58.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -29,11 +29,11 @@ "stats", "utils" ], - "Hash": "71476c1d88d1ebdf31580e5a257d5d31" + "Hash": "a3142b2a022b8174ca675bc8b80cdc4e" }, "Matrix": { "Package": "Matrix", - "Version": "1.4-1", + "Version": "1.5-4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -45,7 +45,7 @@ "stats", "utils" ], - "Hash": "699c47c606293bdfbc9fd78a93c9c8fe" + "Hash": "e779c7d9f35cc364438578f334cffee2" }, "R6": { "Package": "R6", @@ -69,26 +69,14 @@ }, "Rcpp": { "Package": "Rcpp", - "Version": "1.0.10", + "Version": "1.0.11", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods", "utils" ], - "Hash": "e749cae40fa9ef469b6050959517453c" - }, - "SqlRender": { - "Package": "SqlRender", - "Version": "1.14.0", - "Source": "Repository", - "Repository": "CRAN", - "Requirements": [ - "checkmate", - "rJava", - "rlang" - ], - "Hash": "9bc9e33cbab6a5f99bcee12c4ce4b7c9" + "Hash": "ae6cbbe1492f4de79c45fce06f967ce8" }, "anytime": { "Package": "anytime", @@ -104,23 +92,13 @@ }, "askpass": { "Package": "askpass", - "Version": "1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "sys" ], - "Hash": "e8a22846fff485f0be3770c2da758713" - }, - "backports": { - "Package": "backports", - "Version": "1.4.1", - "Source": "Repository", - "Repository": "CRAN", - "Requirements": [ - "R" - ], - "Hash": "c39fbec8a30d23e721980b8afb31984c" + "Hash": "cad6cf7f1d5f6e906700b9d3e718c796" }, "base64enc": { "Package": "base64enc", @@ -134,7 +112,7 @@ }, "bslib": { "Package": "bslib", - "Version": "0.4.2", + "Version": "0.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -150,55 +128,45 @@ "rlang", "sass" ], - "Hash": "a7fbf03946ad741129dc81098722fca1" + "Hash": "283015ddfbb9d7bf15ea9f0b5698f0d9" }, "cachem": { "Package": "cachem", - "Version": "1.0.7", + "Version": "1.0.8", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "fastmap", "rlang" ], - "Hash": "cda74447c42f529de601fe4d4050daef" - }, - "checkmate": { - "Package": "checkmate", - "Version": "2.1.0", - "Source": "Repository", - "Repository": "CRAN", - "Requirements": [ - "R", - "backports", - "utils" - ], - "Hash": "147e4db6909d8814bb30f671b49d7e06" + "Hash": "c35768291560ce302c0a6589f92e837d" }, "cli": { "Package": "cli", - "Version": "3.6.0", + "Version": "3.6.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "3177a5a16c243adc199ba33117bd9657" + "Hash": "89e6d8219950eac806ae0c489052048a" }, "clock": { "Package": "clock", - "Version": "0.6.1", + "Version": "0.7.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", + "cli", "cpp11", + "lifecycle", "rlang", "tzdb", "vctrs" ], - "Hash": "db6b0e88fa092982ecf56322b47be0fe" + "Hash": "3d8a84cdf9f6f8564531c49b70f3833d" }, "colorspace": { "Package": "colorspace", @@ -223,10 +191,13 @@ }, "cpp11": { "Package": "cpp11", - "Version": "0.4.3", + "Version": "0.4.6", "Source": "Repository", "Repository": "CRAN", - "Hash": "ed588261931ee3be2c700d22e94a29ab" + "Requirements": [ + "R" + ], + "Hash": "707fae4bbf73697ec8d85f9d7076c061" }, "crayon": { "Package": "crayon", @@ -255,13 +226,13 @@ }, "curl": { "Package": "curl", - "Version": "5.0.0", + "Version": "5.1.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "e4f97056611e8e6b8b852d13b7400cf1" + "Hash": "9123f3ef96a2c1a93927d828b2fe7d4c" }, "data.table": { "Package": "data.table", @@ -276,18 +247,18 @@ }, "digest": { "Package": "digest", - "Version": "0.6.31", + "Version": "0.6.33", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "8b708f296afd9ae69f450f9640be8990" + "Hash": "b18a9cf3c003977b0cc49d5e76ebe48d" }, "dplyr": { "Package": "dplyr", - "Version": "1.1.1", + "Version": "1.1.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -306,7 +277,7 @@ "utils", "vctrs" ], - "Hash": "eb5742d256a0d9306d85ea68756d8187" + "Hash": "e85ffbebaad5f70e1a2e2ef4302b4949" }, "ellipsis": { "Package": "ellipsis", @@ -321,18 +292,18 @@ }, "evaluate": { "Package": "evaluate", - "Version": "0.20", + "Version": "0.22", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "4b68aa51edd89a0e044a66e75ae3cc6c" + "Hash": "66f39c7a21e03c4dcb2c2d21d738d603" }, "fansi": { "Package": "fansi", - "Version": "1.0.4", + "Version": "1.0.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -340,7 +311,7 @@ "grDevices", "utils" ], - "Hash": "1d9e7ad3c8312a192dea7d3db0274fde" + "Hash": "3e8583a60163b4bc1a80016e63b9959e" }, "farver": { "Package": "farver", @@ -358,7 +329,7 @@ }, "fontawesome": { "Package": "fontawesome", - "Version": "0.5.0", + "Version": "0.5.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -366,18 +337,18 @@ "htmltools", "rlang" ], - "Hash": "e80750aec5717dedc019ad7ee40e4a7c" + "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" }, "fs": { "Package": "fs", - "Version": "1.6.1", + "Version": "1.6.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "f4dcd23b67e33d851d2079f703e8b985" + "Hash": "47b5f30c720c23999b913a1a635cf0bb" }, "generics": { "Package": "generics", @@ -392,7 +363,7 @@ }, "ggplot2": { "Package": "ggplot2", - "Version": "3.4.2", + "Version": "3.4.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -413,7 +384,7 @@ "vctrs", "withr" ], - "Hash": "3a147ee02e85a8941aad9909f1b43b7b" + "Hash": "313d31eff2274ecf4c1d3581db7241f9" }, "glue": { "Package": "glue", @@ -428,7 +399,7 @@ }, "gtable": { "Package": "gtable", - "Version": "0.3.3", + "Version": "0.3.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -439,7 +410,7 @@ "lifecycle", "rlang" ], - "Hash": "b44addadb528a0d227794121c00572a0" + "Hash": "b29cf3031f49b04ab9c852c912547eef" }, "highr": { "Package": "highr", @@ -454,7 +425,7 @@ }, "htmltools": { "Package": "htmltools", - "Version": "0.5.5", + "Version": "0.5.6.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -467,7 +438,7 @@ "rlang", "utils" ], - "Hash": "ba0240784ad50a62165058a27459304a" + "Hash": "1e12fe667316a76508898839ecfb2d00" }, "htmlwidgets": { "Package": "htmlwidgets", @@ -486,7 +457,7 @@ }, "httpuv": { "Package": "httpuv", - "Version": "1.6.9", + "Version": "1.6.11", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -497,11 +468,11 @@ "promises", "utils" ], - "Hash": "1046aa31a57eae8b357267a56a0b6d8b" + "Hash": "838602f54e32c1a0f8cc80708cefcefa" }, "httr": { "Package": "httr", - "Version": "1.4.5", + "Version": "1.4.7", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -512,7 +483,7 @@ "mime", "openssl" ], - "Hash": "f6844033201269bec3ca0097bc6c97b3" + "Hash": "ac107251d9d9fd72f0ca8049988f1d7f" }, "isoband": { "Package": "isoband", @@ -537,17 +508,17 @@ }, "jsonlite": { "Package": "jsonlite", - "Version": "1.8.4", + "Version": "1.8.7", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods" ], - "Hash": "a4269a09a9b865579b2635c77e572374" + "Hash": "266a20443ca13c65688b2116d5220f76" }, "knitr": { "Package": "knitr", - "Version": "1.42", + "Version": "1.44", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -559,33 +530,33 @@ "xfun", "yaml" ], - "Hash": "8329a9bcc82943c8069104d4be3ee22d" + "Hash": "60885b9f746c9dfaef110d070b5f7dc0" }, "labeling": { "Package": "labeling", - "Version": "0.4.2", + "Version": "0.4.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "graphics", "stats" ], - "Hash": "3d5108641f47470611a32d0bdf357a72" + "Hash": "b64ec208ac5bc1852b285f665d6368b3" }, "later": { "Package": "later", - "Version": "1.3.0", + "Version": "1.3.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "Rcpp", "rlang" ], - "Hash": "7e7b457d7766bc47f2a5f21cc2984f8e" + "Hash": "40401c9cf2bc2259dfe83311c9384710" }, "lattice": { "Package": "lattice", - "Version": "0.20-45", + "Version": "0.21-8", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -596,7 +567,7 @@ "stats", "utils" ], - "Hash": "b64cdbb2b340437c4ee047a1f4c4377b" + "Hash": "0b8a6d63c8770f02a8b5635f3c431e6b" }, "lazyeval": { "Package": "lazyeval", @@ -644,7 +615,7 @@ }, "mgcv": { "Package": "mgcv", - "Version": "1.8-40", + "Version": "1.8-42", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -657,7 +628,7 @@ "stats", "utils" ], - "Hash": "c6b2fdb18cf68ab613bd564363e1ba0d" + "Hash": "3460beba7ccc8946249ba35327ba902a" }, "mime": { "Package": "mime", @@ -682,7 +653,7 @@ }, "nlme": { "Package": "nlme", - "Version": "3.1-158", + "Version": "3.1-162", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -692,17 +663,17 @@ "stats", "utils" ], - "Hash": "9469aeaeddf4f48a7ac70877d0b7ba36" + "Hash": "0984ce8da8da9ead8643c5cbbb60f83e" }, "openssl": { "Package": "openssl", - "Version": "2.0.6", + "Version": "2.1.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "askpass" ], - "Hash": "0f7cd2962e3044bb940cca4f4b5cecbe" + "Hash": "2a0dc8c6adfb6f032e4d4af82d258ab5" }, "pillar": { "Package": "pillar", @@ -733,7 +704,7 @@ }, "plotly": { "Package": "plotly", - "Version": "4.10.1", + "Version": "4.10.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -761,26 +732,27 @@ "vctrs", "viridisLite" ], - "Hash": "3781cf6971c6467fa842a63725bbee9e" + "Hash": "56914cc61df53f2d0283d5498680867e" }, "promises": { "Package": "promises", - "Version": "1.2.0.1", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R6", "Rcpp", + "fastmap", "later", "magrittr", "rlang", "stats" ], - "Hash": "4ab2c43adb4d4699cf3690acd378d75d" + "Hash": "0d8a15c9d000970ada1ab21405387dee" }, "purrr": { "Package": "purrr", - "Version": "1.0.1", + "Version": "1.0.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -791,18 +763,7 @@ "rlang", "vctrs" ], - "Hash": "d71c815267c640f17ddbf7f16144b4bb" - }, - "rJava": { - "Package": "rJava", - "Version": "1.0-6", - "Source": "Repository", - "Repository": "CRAN", - "Requirements": [ - "R", - "methods" - ], - "Hash": "0415819f6baa75d86d52483f7292b623" + "Hash": "1cba04a4e9414bdefc9dcaa99649a8dc" }, "rappdirs": { "Package": "rappdirs", @@ -816,13 +777,13 @@ }, "reactR": { "Package": "reactR", - "Version": "0.4.4", + "Version": "0.5.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "htmltools" ], - "Hash": "75389c8091eb14ee21c6bc87a88b3809" + "Hash": "c9014fd1a435b2d790dd506589cb24e5" }, "reactable": { "Package": "reactable", @@ -841,28 +802,28 @@ }, "renv": { "Package": "renv", - "Version": "0.17.3", + "Version": "1.0.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "utils" ], - "Hash": "4543b8cd233ae25c6aba8548be9e747e" + "Hash": "41b847654f567341725473431dd0d5ab" }, "rlang": { "Package": "rlang", - "Version": "1.1.0", + "Version": "1.1.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "dc079ccd156cde8647360f473c1fa718" + "Hash": "a85c767b55f0bf9b7ad16c6d7baee5bb" }, "rmarkdown": { "Package": "rmarkdown", - "Version": "2.21", + "Version": "2.25", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -882,11 +843,11 @@ "xfun", "yaml" ], - "Hash": "493df4ae51e2e984952ea4d5c75786a3" + "Hash": "d65e35823c817f09f4de424fcdfa812a" }, "sass": { "Package": "sass", - "Version": "0.4.5", + "Version": "0.4.7", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -896,7 +857,7 @@ "rappdirs", "rlang" ], - "Hash": "2bb4371a4c80115518261866eab6ab11" + "Hash": "6bd4d33b50ff927191ec9acbf52fd056" }, "scales": { "Package": "scales", @@ -918,7 +879,7 @@ }, "shiny": { "Package": "shiny", - "Version": "1.7.4", + "Version": "1.7.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -948,11 +909,11 @@ "withr", "xtable" ], - "Hash": "c2eae3d8c670fa9dfa35a12066f4a1d5" + "Hash": "5ec01cc255f2138fc2f0dc74d2b1a1a1" }, "shinyWidgets": { "Package": "shinyWidgets", - "Version": "0.7.6", + "Version": "0.8.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -966,7 +927,7 @@ "sass", "shiny" ], - "Hash": "fd889b32caa37b8ed9b1e9e7ef1564bc" + "Hash": "c6acc72327e63668bbc7bd258ee54132" }, "shinycssloaders": { "Package": "shinycssloaders", @@ -1024,10 +985,10 @@ }, "sys": { "Package": "sys", - "Version": "3.4.1", + "Version": "3.4.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "34c16f1ef796057bfa06d3f4ff818a5d" + "Hash": "3a1be13d68d47a8cd0bfd74739ca1555" }, "tibble": { "Package": "tibble", @@ -1089,24 +1050,24 @@ }, "tinytex": { "Package": "tinytex", - "Version": "0.44", + "Version": "0.48", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "xfun" ], - "Hash": "c0f007e2eeed7722ce13d42b84a22e07" + "Hash": "8f96d229b7311beb32b94cf413b13f84" }, "tzdb": { "Package": "tzdb", - "Version": "0.3.0", + "Version": "0.4.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "cpp11" ], - "Hash": "b2e1cbce7c903eaf23ec05c58e59fb5e" + "Hash": "f561504ec2897f4d46f0c7657e488ae1" }, "utf8": { "Package": "utf8", @@ -1120,7 +1081,7 @@ }, "vctrs": { "Package": "vctrs", - "Version": "0.6.1", + "Version": "0.6.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1130,21 +1091,21 @@ "lifecycle", "rlang" ], - "Hash": "06eceb3a5d716fd0654cc23ca3d71a99" + "Hash": "266c1ca411266ba8f365fcc726444b87" }, "viridisLite": { "Package": "viridisLite", - "Version": "0.4.1", + "Version": "0.4.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "62f4b5da3e08d8e5bcba6cac15603f70" + "Hash": "c826c7c4241b6fc89ff55aaea3fa7491" }, "withr": { "Package": "withr", - "Version": "2.5.0", + "Version": "2.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1153,18 +1114,18 @@ "graphics", "stats" ], - "Hash": "c0e49a9760983e81e55cdd9be92e7182" + "Hash": "d77c6f74be05c33164e33fbc85540cae" }, "xfun": { "Package": "xfun", - "Version": "0.38", + "Version": "0.40", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "stats", "tools" ], - "Hash": "1ed71215d45e85562d3b1b29a068ccec" + "Hash": "be07d23211245fc7d4209f54c4e4ffc8" }, "xtable": { "Package": "xtable", diff --git a/inst/shiny/renv/activate.R b/inst/shiny/renv/activate.R index a8fdc32..cb5401f 100644 --- a/inst/shiny/renv/activate.R +++ b/inst/shiny/renv/activate.R @@ -2,11 +2,27 @@ local({ # the requested version of renv - version <- "0.17.3" + 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,25 +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 } - `%??%` <- function(x, y) { - if (is.null(x)) y else x + catf <- function(fmt, ..., appendLF = TRUE) { + + quiet <- getOption("renv.bootstrap.quiet", default = FALSE) + if (quiet) + return(invisible()) + + msg <- sprintf(fmt, ...) + cat(msg, file = stdout(), sep = if (appendLF) "\n" else "") + + invisible(msg) + + } + + header <- function(label, + ..., + prefix = "#", + suffix = "-", + n = min(getOption("width"), 78)) + { + label <- sprintf(label, ...) + n <- max(n - nchar(label) - nchar(prefix) - 2L, 8L) + if (n <= 0) + return(paste(prefix, label)) + + tail <- paste(rep.int(suffix, n), collapse = "") + paste0(prefix, " ", label, " ", tail) + + } + + startswith <- function(string, prefix) { + substring(string, 1, nchar(prefix)) == prefix } bootstrap <- function(version, library) { + friendly <- renv_bootstrap_version_friendly(version) + section <- header(sprintf("Bootstrapping renv %s", friendly)) + catf(section) + # attempt to download renv - tarball <- tryCatch(renv_bootstrap_download(version), error = identity) - if (inherits(tarball, "error")) - stop("failed to download renv ", version) + catf("- Downloading renv ... ", appendLF = FALSE) + withCallingHandlers( + tarball <- renv_bootstrap_download(version), + error = function(err) { + catf("FAILED") + stop("failed to download:\n", conditionMessage(err)) + } + ) + catf("OK") + on.exit(unlink(tarball), add = TRUE) # now attempt to install - status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity) - if (inherits(status, "error")) - stop("failed to install renv ", version) + catf("- Installing renv ... ", appendLF = FALSE) + withCallingHandlers( + status <- renv_bootstrap_install(version, tarball, library), + error = function(err) { + catf("FAILED") + stop("failed to install:\n", conditionMessage(err)) + } + ) + catf("OK") + + # add empty line to break up bootstrapping from normal output + catf("") + return(invisible()) } renv_bootstrap_tests_running <- function() { @@ -108,13 +174,6 @@ local({ if (!inherits(repos, "error") && length(repos)) return(repos) - # if we're testing, re-use the test repositories - if (renv_bootstrap_tests_running()) { - repos <- getOption("renv.tests.repos") - if (!is.null(repos)) - return(repos) - } - # retrieve current repos repos <- getOption("repos") @@ -158,33 +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") } @@ -248,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" @@ -266,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 } @@ -329,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( @@ -338,14 +391,11 @@ local({ condition = identity ) - if (identical(status, 0L)) { - message("OK") + if (identical(status, 0L)) return(destfile) - } } - message("FAILED") return(FALSE) } @@ -368,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) @@ -377,10 +427,7 @@ local({ } - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) - + catf("- Using local tarball '%s'.", tarball) tarball } @@ -407,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) @@ -418,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", @@ -445,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) } @@ -667,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-") @@ -718,7 +858,7 @@ local({ hooks <- getHook("renv::autoload") for (hook in hooks) if (is.function(hook)) - tryCatch(hook(), error = warning) + tryCatch(hook(), error = warnify) # load the project renv::load(project) @@ -859,6 +999,40 @@ local({ } + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { + sha <- sha %||% attr(version, "sha", exact = TRUE) + parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = "") + } + + renv_bootstrap_exec <- function(project, libpath, version) { + if (!renv_bootstrap_load(project, libpath, version)) + renv_bootstrap_run(version, libpath) + } + + renv_bootstrap_run <- function(version, libpath) { + + # perform bootstrap + bootstrap(version, libpath) + + # exit early if we're just testing bootstrap + if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) + return(TRUE) + + # try again to load + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + return(renv::load(project = getwd())) + } + + # failed to download or load renv; warn the user + msg <- c( + "Failed to find an renv installation: the project will not be loaded.", + "Use `renv::activate()` to re-initialize the project." + ) + + warning(paste(msg, collapse = "\n"), call. = FALSE) + + } renv_json_read <- function(file = NULL, text = NULL) { @@ -998,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/inst/shiny/renv/settings.dcf b/inst/shiny/renv/settings.dcf deleted file mode 100644 index 169d82f..0000000 --- a/inst/shiny/renv/settings.dcf +++ /dev/null @@ -1,10 +0,0 @@ -bioconductor.version: -external.libraries: -ignored.packages: -package.dependency.fields: Imports, Depends, LinkingTo -r.version: -snapshot.type: implicit -use.cache: TRUE -vcs.ignore.cellar: TRUE -vcs.ignore.library: TRUE -vcs.ignore.local: TRUE diff --git a/inst/shiny/renv/settings.json b/inst/shiny/renv/settings.json deleted file mode 100644 index 1a06760..0000000 --- a/inst/shiny/renv/settings.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "bioconductor.version": null, - "external.libraries": [], - "ignored.packages": [], - "package.dependency.fields": [ - "Imports", - "Depends", - "LinkingTo" - ], - "r.version": null, - "snapshot.type": "implicit", - "use.cache": true, - "vcs.ignore.cellar": true, - "vcs.ignore.library": true, - "vcs.ignore.local": true, - "vcs.manage.ignores": true -} diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 8bed03f..f46815e 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -108,7 +108,7 @@ shinyServer(function(input, output, session) { for (i in (1:length(selectedCdmTables))) { domainTableData <- - dataFromRds()[[SqlRender::snakeCaseToCamelCase(selectedCdmTables[[i]])]] %>% + dataFromRds()[[snakeCaseToCamelCase(selectedCdmTables[[i]])]] %>% dplyr::filter(personId == subjectIds()[subject$index]) %>% dplyr::mutate(cdmTable = selectedCdmTables[[i]]) @@ -319,7 +319,7 @@ shinyServer(function(input, output, session) { cdmTable) colnames(data) <- - SqlRender::camelCaseToTitleCase(colnames(data)) + camelCaseToTitleCase(colnames(data)) dataTable <- reactable::reactable( data = data, diff --git a/inst/shiny/ui.R b/inst/shiny/ui.R index c40e3c1..1ef867c 100644 --- a/inst/shiny/ui.R +++ b/inst/shiny/ui.R @@ -28,8 +28,8 @@ column( checkboxGroupInput( "cdmTables", label = "CDM Table", - choices = SqlRender::camelCaseToTitleCase(tables), - selected = SqlRender::camelCaseToTitleCase( + choices = camelCaseToTitleCase(tables), + selected = camelCaseToTitleCase( c( "visitOccurrence", "conditionOccurrence",