diff --git a/.Rprofile b/.Rprofile index c044f24..81b960f 100644 --- a/.Rprofile +++ b/.Rprofile @@ -1 +1 @@ -source("renv/activate.R") +source("renv/activate.R") diff --git a/api.R b/api.R index 3211721..ec69972 100644 --- a/api.R +++ b/api.R @@ -1,101 +1,232 @@ # Setup ------------------------------------------------------------------------ library(arrow) +library(assertthat) library(aws.s3) library(ccao) library(dplyr) library(lightsnip) +library(tibble) library(plumber) +library(purrr) +library(rapidoc) library(vetiver) source("generics.R") +# Define constants +dvc_bucket_pre_2024 <- "s3://ccao-data-dvc-us-east-1" +dvc_bucket_post_2024 <- "s3://ccao-data-dvc-us-east-1/files/md5" +base_url_prefix <- "/predict" + # Read AWS creds from Docker secrets if (file.exists("/run/secrets/ENV_FILE")) { readRenviron("/run/secrets/ENV_FILE") -} else { +} else if (file.exists("secrets/ENV_FILE")) { readRenviron("secrets/ENV_FILE") } readRenviron(".env") # Get the model run attributes at runtime from env vars -dvc_bucket <- Sys.getenv("AWS_S3_DVC_BUCKET") run_bucket <- Sys.getenv("AWS_S3_MODEL_BUCKET") -run_id <- Sys.getenv("AWS_S3_MODEL_RUN_ID") -run_year <- Sys.getenv("AWS_S3_MODEL_YEAR") api_port <- as.numeric(Sys.getenv("API_PORT", unset = "3636")) - - -# Download Files --------------------------------------------------------------- - -# Grab model fit and recipe objects -temp_file_fit <- tempfile(fileext = ".zip") -aws.s3::save_object( - object = file.path( - run_bucket, "workflow/fit", - paste0("year=", run_year), - paste0(run_id, ".zip") +default_run_id_var_name <- "AWS_S3_DEFAULT_MODEL_RUN_ID" +default_run_id <- Sys.getenv(default_run_id_var_name) + +# The list of runs that will be deployed as possible model endpoints +valid_runs <- rbind( + c( + run_id = "2022-04-27-keen-gabe", + year = "2022", + dvc_bucket = dvc_bucket_pre_2024, + predictors_only = FALSE ), - file = temp_file_fit -) - -temp_file_recipe <- tempfile(fileext = ".rds") -aws.s3::save_object( - object = file.path( - run_bucket, "workflow/recipe", - paste0("year=", run_year), - paste0(run_id, ".rds") + c( + run_id = "2023-03-14-clever-damani", + year = "2023", + dvc_bucket = dvc_bucket_pre_2024, + predictors_only = FALSE + ), + c( + run_id = "2024-02-06-relaxed-tristan", + year = "2024", + dvc_bucket = dvc_bucket_post_2024, + predictors_only = TRUE ), - file = temp_file_recipe + c( + run_id = "2024-03-17-stupefied-maya", + year = "2024", + dvc_bucket = dvc_bucket_post_2024, + predictors_only = TRUE + ) +) %>% + as_tibble() + +assert_that( + default_run_id %in% valid_runs$run_id, + msg = sprintf( + "%s must be a valid run_id - got '%s', expected one of: %s", + default_run_id_var_name, + default_run_id, + paste(valid_runs$run_id, collapse = ", ") + ) ) -# Grab metadata file for the specified run -metadata <- read_parquet( - file.path( - run_bucket, "metadata", - paste0("year=", run_year), - paste0(run_id, ".parquet") +# Given a run ID and year, return a model object that can be used to power a +# Plumber/vetiver API endpoint +get_model_from_run <- function(run_id, year, dvc_bucket, predictors_only) { + # Download Files ------------------------------------------------------------- + + # Grab model fit and recipe objects + temp_file_fit <- tempfile(fileext = ".zip") + aws.s3::save_object( + object = file.path( + run_bucket, "workflow/fit", + paste0("year=", year), + paste0(run_id, ".zip") + ), + file = temp_file_fit ) -) -# Load the training data used for this model -training_data_md5 <- metadata$dvc_md5_training_data -training_data <- read_parquet( - file.path( - dvc_bucket, - substr(training_data_md5, 1, 2), - substr(training_data_md5, 3, nchar(training_data_md5)) + temp_file_recipe <- tempfile(fileext = ".rds") + aws.s3::save_object( + object = file.path( + run_bucket, "workflow/recipe", + paste0("year=", year), + paste0(run_id, ".rds") + ), + file = temp_file_recipe + ) + + # Grab metadata file for the specified run + metadata <- read_parquet( + file.path( + run_bucket, "metadata", + paste0("year=", year), + paste0(run_id, ".parquet") + ) ) -) + # Load the training data used for this model + training_data_md5 <- metadata$dvc_md5_training_data + training_data <- read_parquet( + file.path( + dvc_bucket, + substr(training_data_md5, 1, 2), + substr(training_data_md5, 3, nchar(training_data_md5)) + ) + ) -# Load Model ------------------------------------------------------------------- -# Load fit and recipe from file -fit <- lightsnip::lgbm_load(temp_file_fit) -recipe <- readRDS(temp_file_recipe) + # Load Model ----------------------------------------------------------------- -# Extract a sample row of predictors to use for the API docs -predictors <- recipe$var_info %>% - filter(role == "predictor") %>% - pull(variable) -ptype_tbl <- training_data %>% - filter(meta_pin == "15251030220000") %>% - select(all_of(predictors)) -ptype <- vetiver_create_ptype(model = fit, save_prototype = ptype_tbl) + # Load fit and recipe from file + fit <- lightsnip::lgbm_load(temp_file_fit) + recipe <- readRDS(temp_file_recipe) + # Extract a sample row of data to use for the API docs + ptype_tbl <- training_data %>% + filter(meta_pin == "15251030220000") -# Create API ------------------------------------------------------------------- + # If the model recipe is configured to allow it, strip all chars except + # for the predictors from the example row + if (predictors_only) { + predictors <- recipe$var_info %>% + filter(role == "predictor") %>% + pull(variable) + ptype_tbl <- ptype_tbl %>% + filter(meta_pin == "15251030220000") %>% + select(all_of(predictors)) + } -# Create model object and populate metadata -model <- vetiver_model(fit, "LightGBM", save_prototype = ptype) -model$recipe <- recipe -model$pv$round_type <- metadata$pv_round_type -model$pv$round_break <- metadata$pv_round_break[[1]] -model$pv$round_to_nearest <- metadata$pv_round_to_nearest[[1]] + ptype <- vetiver_create_ptype(model = fit, save_prototype = ptype_tbl) -# Start API -pr() %>% - vetiver_api(model) %>% - pr_run( - host = "0.0.0.0", - port = api_port + + # Create API ----------------------------------------------------------------- + + # Create model object and populate metadata + model <- vetiver_model(fit, "LightGBM", save_prototype = ptype) + model$recipe <- recipe + model$pv$round_type <- metadata$pv_round_type + model$pv$round_break <- metadata$pv_round_break[[1]] + model$pv$round_to_nearest <- metadata$pv_round_to_nearest[[1]] + + return(model) +} + +# Filter the valid runs for the run marked as default +default_run <- valid_runs %>% + dplyr::filter(run_id == default_run_id) %>% + dplyr::slice_head() + +# Retrieve paths and model objects for all endpoints to be deployed +all_endpoints <- list() +for (i in seq_len(nrow(valid_runs))) { + run <- valid_runs[i, ] + model <- get_model_from_run( + run$run_id, run$year, run$dvc_bucket, run$predictors_only + ) + all_endpoints <- append(all_endpoints, list(list( + path = glue::glue("{base_url_prefix}/{run$run_id}"), + model = model + ))) + # If this is the default endpoint, add an extra entry for it + if (run$run_id == default_run$run_id) { + all_endpoints <- append(all_endpoints, list(list( + path = glue::glue("{base_url_prefix}"), + model = model + ))) + } +} + +# Instantiate a Plumber router for the API. Note that we have to use direct +# Plumber calls instead of using vetiver to define the API since vetiver +# currently has bad support for deploying multiple models on the same API +router <- pr() %>% + plumber::pr_set_debug(rlang::is_interactive()) %>% + plumber::pr_set_serializer(plumber::serializer_unboxed_json(null = "null")) + +# Add Plumber POST enpdoints for each model +for (i in seq_along(all_endpoints)) { + endpoint <- all_endpoints[[i]] + router <- plumber::pr_post( + router, endpoint$path, handler_predict(endpoint$model) + ) +} + +# Define a function to override the openapi spec for the API, using +# each model's prototype for docs and examples +modify_spec <- function(spec) { + spec$info$title <- "CCAO Residential AVM API" + spec$info$description <- ( + "API for returning predicted values using CCAO residential AVMs" + ) + + for (i in seq_along(all_endpoints)) { + endpoint <- all_endpoints[[i]] + ptype <- endpoint$model$prototype + path <- endpoint$path + orig_post <- pluck(spec, "paths", path, "post") + spec$paths[[path]]$post <- list( + summary = glue_spec_summary(ptype), + requestBody = map_request_body(ptype), + responses = orig_post$responses + ) + } + + return(spec) +} + +router <- plumber::pr_set_api_spec(router, api = modify_spec) %>% + plumber::pr_set_docs( + "rapidoc", + header_color = "#F2C6AC", + primary_color = "#8C2D2D", + use_path_in_nav_bar = TRUE, + show_method_in_nav_bar = "as-plain-text" ) + +# Start API +pr_run( + router, + host = "0.0.0.0", + port = api_port +) diff --git a/docker-compose.yaml b/docker-compose.yaml index 05ec56d..4357d3d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,16 +3,13 @@ services: plumber: build: . image: ${CCAO_REGISTRY_URL}/api-res-avm:latest - privileged: true ports: - "${API_PORT}:${API_PORT}" networks: - api-res-avm-net environment: - - AWS_S3_DVC_BUCKET - AWS_S3_MODEL_BUCKET - - AWS_S3_MODEL_RUN_ID - - AWS_S3_MODEL_YEAR + - AWS_S3_DEFAULT_MODEL_RUN_ID - API_PORT secrets: - ENV_FILE diff --git a/generics.R b/generics.R index 0e52512..4dc65ca 100644 --- a/generics.R +++ b/generics.R @@ -10,11 +10,6 @@ vetiver_create_meta._lgb.Booster <- function(model, metadata) { } -handler_startup._lgb.Booster <- function(vetiver_model) { - attach_pkgs(vetiver_model$metadata$required_pkgs) -} - - handler_predict._lgb.Booster <- function(vetiver_model, ...) { ptype <- vetiver_model$ptype diff --git a/renv.lock b/renv.lock index 8455855..45c97d0 100644 --- a/renv.lock +++ b/renv.lock @@ -1,38 +1,38 @@ { "R": { - "Version": "4.2.2", + "Version": "4.4.0", "Repositories": [ { "Name": "CRAN", - "URL": "https://cran.rstudio.com" + "URL": "https://cloud.r-project.org" } ] }, "Packages": { "DiceDesign": { "Package": "DiceDesign", - "Version": "1.9", + "Version": "1.10", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "b7b812ae4484d4bbf0a0baac72e8fc01" + "Hash": "ac8b12951882c375d1a14f64c93e78f1" }, "KernSmooth": { "Package": "KernSmooth", - "Version": "2.23-20", + "Version": "2.23-22", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "stats" ], - "Hash": "8dcfa99b14c296bc9f1fd64d52fd3ce7" + "Hash": "2fecebc3047322fa5930f74fae5de70f" }, "MASS": { "Package": "MASS", - "Version": "7.3-58.2", + "Version": "7.3-60", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -43,15 +43,16 @@ "stats", "utils" ], - "Hash": "e02d1a0f6122fd3e634b25b433704344" + "Hash": "a56a6365b3fa73293ea8d084be0d9bb0" }, "Matrix": { "Package": "Matrix", - "Version": "1.5-3", + "Version": "1.6-5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", + "grDevices", "graphics", "grid", "lattice", @@ -59,7 +60,7 @@ "stats", "utils" ], - "Hash": "4006dffe49958d2dd591c17e61e60591" + "Hash": "8c7115cd3a0e048bda2a7cd110549f7a" }, "R6": { "Package": "R6", @@ -83,14 +84,14 @@ }, "Rcpp": { "Package": "Rcpp", - "Version": "1.0.10", + "Version": "1.0.12", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods", "utils" ], - "Hash": "e749cae40fa9ef469b6050959517453c" + "Hash": "5ea2700d21e038ace58269ecdbeb9ec0" }, "SQUAREM": { "Package": "SQUAREM", @@ -104,7 +105,7 @@ }, "arrow": { "Package": "arrow", - "Version": "11.0.0.2", + "Version": "15.0.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -122,17 +123,17 @@ "utils", "vctrs" ], - "Hash": "aac084fe3bbdddc61dfbca3077e1995d" + "Hash": "85c24dd7844977e4a680ba28f576125c" }, "askpass": { "Package": "askpass", - "Version": "1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "sys" ], - "Hash": "e8a22846fff485f0be3770c2da758713" + "Hash": "cad6cf7f1d5f6e906700b9d3e718c796" }, "assertthat": { "Package": "assertthat", @@ -146,19 +147,19 @@ }, "assessr": { "Package": "assessr", - "Version": "0.5.2", + "Version": "0.6.0", "Source": "GitHub", "RemoteType": "github", "RemoteHost": "api.github.com", "RemoteUsername": "ccao-data", "RemoteRepo": "assessr", "RemoteRef": "master", - "RemoteSha": "dcfc0f0585462cc87cab42b965d16ec4c5546256", + "RemoteSha": "fcef4b9d68b53ea42f324a7984dec043daadeb6f", "Requirements": [ "R", "stats" ], - "Hash": "2bb19b867910fb7334778ec519fac8d2" + "Hash": "76ec072b6db1b49c2ff3b9dfc1e5e8c6" }, "aws.s3": { "Package": "aws.s3", @@ -224,21 +225,22 @@ }, "bundle": { "Package": "bundle", - "Version": "0.1.0", + "Version": "0.1.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ + "R", "glue", "purrr", "rlang", "utils", "withr" ], - "Hash": "eddb272b43e01d3d667b1304aeafed5a" + "Hash": "ed93653b17cf6f20ebd97a87862f702e" }, "butcher": { "Package": "butcher", - "Version": "0.3.1", + "Version": "0.3.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -252,18 +254,18 @@ "utils", "vctrs" ], - "Hash": "30aee833901f64898b9f9a6b248bac04" + "Hash": "951e96dd017c1cbf446bbd7d94d5fb6f" }, "ccao": { "Package": "ccao", - "Version": "1.2.2", + "Version": "1.3.0", "Source": "GitHub", "RemoteType": "github", "RemoteHost": "api.github.com", "RemoteUsername": "ccao-data", "RemoteRepo": "ccao", "RemoteRef": "master", - "RemoteSha": "74737102c48ce07b769a10f42693d9c2c958e9ef", + "RemoteSha": "866392917a9e6eab5fb34b17ff63494e816c9bec", "Remotes": "ccao-data/assessr", "Requirements": [ "R", @@ -273,11 +275,25 @@ "rlang", "tidyr" ], - "Hash": "2aaaeceb70766ef2dc175999eb4aa0ad" + "Hash": "415f894b9726d9ff4c5605e2329dc7d6" + }, + "cereal": { + "Package": "cereal", + "Version": "0.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "jsonlite", + "rlang", + "tibble", + "vctrs" + ], + "Hash": "a87b608b2e9d7a632538803391e127b3" }, "class": { "Package": "class", - "Version": "7.3-21", + "Version": "7.3-22", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -286,18 +302,18 @@ "stats", "utils" ], - "Hash": "8ae0d4328e2eb3a582dfd5391a3663b7" + "Hash": "f91f6b29f38b8c280f2b9477787d4bb2" }, "cli": { "Package": "cli", - "Version": "3.6.0", + "Version": "3.6.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "3177a5a16c243adc199ba33117bd9657" + "Hash": "1216ac65ac55ec0058a6f75d7ca0fd52" }, "clipr": { "Package": "clipr", @@ -311,17 +327,19 @@ }, "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" }, "codetools": { "Package": "codetools", @@ -349,10 +367,13 @@ }, "cpp11": { "Package": "cpp11", - "Version": "0.4.3", + "Version": "0.4.7", "Source": "Repository", "Repository": "CRAN", - "Hash": "ed588261931ee3be2c700d22e94a29ab" + "Requirements": [ + "R" + ], + "Hash": "5a295d7d963cc5035284dcdbaf334f4e" }, "crayon": { "Package": "crayon", @@ -368,28 +389,41 @@ }, "curl": { "Package": "curl", - "Version": "5.0.0", + "Version": "5.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "e4f97056611e8e6b8b852d13b7400cf1" + "Hash": "411ca2c03b1ce5f548345d2fc2685f7a" }, "data.table": { "Package": "data.table", - "Version": "1.14.8", + "Version": "1.15.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "b4c06e554f33344e044ccd7fdca750a9" + "Hash": "8ee9ac56ef633d0c7cab8b2ca87d683e" + }, + "diagram": { + "Package": "diagram", + "Version": "1.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "graphics", + "shape", + "stats" + ], + "Hash": "c7f527c59edc72c4bce63519b8d38752" }, "dials": { "Package": "dials", - "Version": "1.1.0", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -409,22 +443,22 @@ "vctrs", "withr" ], - "Hash": "7f0431d342448a72a154c869f1d9c97e" + "Hash": "999e5fa12058a2bb3a8c204e637e4707" }, "digest": { "Package": "digest", - "Version": "0.6.31", + "Version": "0.6.35", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "8b708f296afd9ae69f450f9640be8990" + "Hash": "698ece7ba5a4fa4559e3d537e7ec3d31" }, "dplyr": { "Package": "dplyr", - "Version": "1.1.0", + "Version": "1.1.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -443,7 +477,7 @@ "utils", "vctrs" ], - "Hash": "d3c34618017e7ae252d46d79a1b9ec32" + "Hash": "fedd9d00c2944ff00a0e2696ccf048ec" }, "ellipsis": { "Package": "ellipsis", @@ -458,7 +492,7 @@ }, "fansi": { "Package": "fansi", - "Version": "1.0.4", + "Version": "1.0.6", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -466,7 +500,7 @@ "grDevices", "utils" ], - "Hash": "1d9e7ad3c8312a192dea7d3db0274fde" + "Hash": "962174cf2aeb5b9eea581522286a911f" }, "farver": { "Package": "farver", @@ -475,27 +509,27 @@ "Repository": "CRAN", "Hash": "8106d78941f34855c440ddb946b8f7a5" }, - "filelock": { - "Package": "filelock", - "Version": "1.0.2", + "fastmap": { + "Package": "fastmap", + "Version": "1.1.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "38ec653c2613bed60052ba3787bd8a2c" + "Hash": "f7736a18de97dea803bde0a2daaafb27" }, "fs": { "Package": "fs", - "Version": "1.6.1", + "Version": "1.6.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "f4dcd23b67e33d851d2079f703e8b985" + "Hash": "15aeb8c27f5ea5161f9f6a641fafd93a" }, "future": { "Package": "future", - "Version": "1.31.0", + "Version": "1.33.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -506,11 +540,11 @@ "parallelly", "utils" ], - "Hash": "f3f0fbe5ce9b77c002f8c5170790538a" + "Hash": "fd7b1d69d16d0d114e4fa82db68f184c" }, "future.apply": { "Package": "future.apply", - "Version": "1.10.0", + "Version": "1.11.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -520,7 +554,7 @@ "parallel", "utils" ], - "Hash": "a930c9ddc317f898e6f5bed7be8dd322" + "Hash": "afe1507511629f44572e6c53b9baeb7c" }, "generics": { "Package": "generics", @@ -535,7 +569,7 @@ }, "ggplot2": { "Package": "ggplot2", - "Version": "3.4.1", + "Version": "3.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -556,29 +590,29 @@ "vctrs", "withr" ], - "Hash": "d494daf77c4aa7f084dbbe6ca5dcaca7" + "Hash": "44c6a2f8202d5b7e878ea274b1092426" }, "globals": { "Package": "globals", - "Version": "0.16.2", + "Version": "0.16.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "codetools" ], - "Hash": "baa9585ab4ce47a9f4618e671778cc6f" + "Hash": "2580567908cafd4f187c1e5a91e98b7f" }, "glue": { "Package": "glue", - "Version": "1.6.2", + "Version": "1.7.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "methods" ], - "Hash": "4f2596dfb05dac67b9dc558e5c6fba2e" + "Hash": "e0b3a53876554bd45879e596cdb10a52" }, "gower": { "Package": "gower", @@ -589,47 +623,51 @@ }, "gtable": { "Package": "gtable", - "Version": "0.3.1", + "Version": "0.3.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", - "grid" + "cli", + "glue", + "grid", + "lifecycle", + "rlang" ], - "Hash": "36b4265fb818f6a342bed217549cd896" + "Hash": "e18861963cbc65a27736e02b3cd3c4a0" }, "hardhat": { "Package": "hardhat", - "Version": "1.2.0", + "Version": "1.3.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", + "cli", "glue", "rlang", "tibble", "vctrs" ], - "Hash": "7cd2660e174e555b05aaeac979dee22b" + "Hash": "921fd010cd788de75a9c71c2c3aee1f2" }, "hms": { "Package": "hms", - "Version": "1.1.2", + "Version": "1.1.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ - "ellipsis", "lifecycle", "methods", "pkgconfig", "rlang", "vctrs" ], - "Hash": "41100392191e1244b887878b533eea91" + "Hash": "b59377caa7ed00fa41808342002138f9" }, "httpuv": { "Package": "httpuv", - "Version": "1.6.9", + "Version": "1.6.15", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -640,11 +678,11 @@ "promises", "utils" ], - "Hash": "1046aa31a57eae8b357267a56a0b6d8b" + "Hash": "d55aa087c47a63ead0f6fc10f8fa1ee0" }, "httr": { "Package": "httr", - "Version": "1.4.5", + "Version": "1.4.7", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -655,11 +693,11 @@ "mime", "openssl" ], - "Hash": "f6844033201269bec3ca0097bc6c97b3" + "Hash": "ac107251d9d9fd72f0ca8049988f1d7f" }, "ipred": { "Package": "ipred", - "Version": "0.9-13", + "Version": "0.9-14", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -671,7 +709,7 @@ "rpart", "survival" ], - "Hash": "83aed0b881998c125aac48cab08141e4" + "Hash": "b25a108cbf4834be7c1b1f46ff30f888" }, "isoband": { "Package": "isoband", @@ -686,39 +724,39 @@ }, "jsonlite": { "Package": "jsonlite", - "Version": "1.8.4", + "Version": "1.8.8", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "methods" ], - "Hash": "a4269a09a9b865579b2635c77e572374" + "Hash": "e1b9c55281c5adc4dd113652d9e26768" }, "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.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "Rcpp", "rlang" ], - "Hash": "7e7b457d7766bc47f2a5f21cc2984f8e" + "Hash": "a3e051d405326b8b0012377434c62b37" }, "lattice": { "Package": "lattice", - "Version": "0.20-45", + "Version": "0.22-5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -729,16 +767,17 @@ "stats", "utils" ], - "Hash": "b64cdbb2b340437c4ee047a1f4c4377b" + "Hash": "7c5e89f04e72d6611c77451f6331a091" }, "lava": { "Package": "lava", - "Version": "1.7.2.1", + "Version": "1.8.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "SQUAREM", + "cli", "future.apply", "grDevices", "graphics", @@ -749,11 +788,11 @@ "survival", "utils" ], - "Hash": "bbc70840ea0f91f34dd9703efe4c96c3" + "Hash": "579303ca1e817d94cea694b319803380" }, "lifecycle": { "Package": "lifecycle", - "Version": "1.0.3", + "Version": "1.0.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -762,11 +801,11 @@ "glue", "rlang" ], - "Hash": "001cecbeac1cff9301bdc3775ee46a86" + "Hash": "b8552d117e1b808b09a832f589b79035" }, "lightgbm": { "Package": "lightgbm", - "Version": "3.3.5", + "Version": "4.3.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -777,9 +816,10 @@ "graphics", "jsonlite", "methods", + "parallel", "utils" ], - "Hash": "e6c3413a4762e6c0cb3a2d32da82a994" + "Hash": "3557a7d44ebdac1cda4cc5b5cbcb7716" }, "lightsnip": { "Package": "lightsnip", @@ -790,7 +830,7 @@ "RemoteUsername": "ccao-data", "RemoteRepo": "lightsnip", "RemoteRef": "master", - "RemoteSha": "f877e887a51f8d423d5ca80719e345e31c4c311c", + "RemoteSha": "ef00b229877e4df5ab60d3049f2eb224794a9161", "Requirements": [ "butcher", "dials", @@ -803,17 +843,17 @@ "tibble", "zip" ], - "Hash": "0d4041d95f45d2d5eaa5aaa1114f2213" + "Hash": "3e4625daa0d644e49c9980888f0e6215" }, "listenv": { "Package": "listenv", - "Version": "0.9.0", + "Version": "0.9.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "4fbd3679ec8ee169ba28d4b1ea7d0e8f" + "Hash": "e2fca3e12e4db979dccc6e519b10a7ee" }, "lobstr": { "Package": "lobstr", @@ -832,7 +872,7 @@ }, "lubridate": { "Package": "lubridate", - "Version": "1.9.2", + "Version": "1.9.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -841,7 +881,7 @@ "methods", "timechange" ], - "Hash": "e25f18436e3efd42c7c590a1c4c15390" + "Hash": "680ad542fbcf801442c83a6ac5a2126c" }, "magrittr": { "Package": "magrittr", @@ -855,7 +895,7 @@ }, "mgcv": { "Package": "mgcv", - "Version": "1.8-42", + "Version": "1.9-1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -868,7 +908,7 @@ "stats", "utils" ], - "Hash": "3460beba7ccc8946249ba35327ba902a" + "Hash": "110ee9d83b496279960e162ac97764ce" }, "mime": { "Package": "mime", @@ -882,18 +922,18 @@ }, "munsell": { "Package": "munsell", - "Version": "0.5.0", + "Version": "0.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "colorspace", "methods" ], - "Hash": "6dfe8bf774944bd5595785e3229d8771" + "Hash": "4fd8900853b746af55b81fda99da7695" }, "nlme": { "Package": "nlme", - "Version": "3.1-162", + "Version": "3.1-163", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -903,11 +943,11 @@ "stats", "utils" ], - "Hash": "0984ce8da8da9ead8643c5cbbb60f83e" + "Hash": "8d1938040a05566f4f7a14af4feadd6b" }, "nnet": { "Package": "nnet", - "Version": "7.3-18", + "Version": "7.3-19", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -915,7 +955,7 @@ "stats", "utils" ], - "Hash": "170da2130d5332bea7d6ede01875ba1d" + "Hash": "2c797b46eea7fb58ede195bc0b1f1138" }, "numDeriv": { "Package": "numDeriv", @@ -929,17 +969,17 @@ }, "openssl": { "Package": "openssl", - "Version": "2.0.5", + "Version": "2.1.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "askpass" ], - "Hash": "b04c27110bf367b4daa93f34f3d58e75" + "Hash": "ea2475b073243d9d338aa8f086ce973e" }, "parallelly": { "Package": "parallelly", - "Version": "1.34.0", + "Version": "1.37.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -947,11 +987,11 @@ "tools", "utils" ], - "Hash": "2a795ec0ddbfe465ca0d6471039631bf" + "Hash": "5410df8d22bd36e616f2a2343dbb328c" }, "parsnip": { "Package": "parsnip", - "Version": "1.0.4", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -976,11 +1016,11 @@ "vctrs", "withr" ], - "Hash": "c798f1abedbea6d64eaf2effd3ff455a" + "Hash": "ace928adf616e06ece817d970faa2d03" }, "pillar": { "Package": "pillar", - "Version": "1.8.1", + "Version": "1.9.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -993,11 +1033,11 @@ "utils", "vctrs" ], - "Hash": "f2316df30902c81729ae9de95ad5a608" + "Hash": "15da5a8412f317beeee6175fbc76f4bb" }, "pins": { "Package": "pins", - "Version": "1.1.0", + "Version": "1.3.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1005,7 +1045,6 @@ "cli", "digest", "ellipsis", - "filelock", "fs", "generics", "glue", @@ -1013,17 +1052,15 @@ "jsonlite", "lifecycle", "magrittr", - "mime", - "openssl", + "purrr", "rappdirs", "rlang", "tibble", "whisker", "withr", - "yaml", - "zip" + "yaml" ], - "Hash": "c6bfa6bbbc54c1d71828ab9167918016" + "Hash": "e240e373ac8805080423d0fb985d87b0" }, "pkgconfig": { "Package": "pkgconfig", @@ -1037,7 +1074,7 @@ }, "plumber": { "Package": "plumber", - "Version": "1.2.1", + "Version": "1.2.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1057,48 +1094,54 @@ "swagger", "webutils" ], - "Hash": "8b65a7a00ef8edc5ddc6fabf0aff1194" + "Hash": "0c671ac357592beb716f19b818b72e50" }, "prettyunits": { "Package": "prettyunits", - "Version": "1.1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "95ef9167b75dde9d2ccc3c7528393e7e" + "Requirements": [ + "R" + ], + "Hash": "6b01fc98b1e86c4f705ce9dcfd2f57c7" }, "prodlim": { "Package": "prodlim", - "Version": "2019.11.13", + "Version": "2023.08.28", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "KernSmooth", "R", "Rcpp", + "data.table", + "diagram", "grDevices", "graphics", "lava", "stats", "survival" ], - "Hash": "c243bf70db3a6631a0c8783152fb7db9" + "Hash": "c73e09a2039a0f75ac0a1e5454b39993" }, "progress": { "Package": "progress", - "Version": "1.2.2", + "Version": "1.2.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ + "R", "R6", "crayon", "hms", "prettyunits" ], - "Hash": "14dc9f7a3c91ebb14ec5bb9208a07061" + "Hash": "f4625e061cb2865f111b47ff163a5ca6" }, "progressr": { "Package": "progressr", - "Version": "0.13.0", + "Version": "0.14.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1106,26 +1149,27 @@ "digest", "utils" ], - "Hash": "376a8ebcc878f9c1395e212548fc297a" + "Hash": "ac50c4ffa8f6a46580dd4d7813add3c4" }, "promises": { "Package": "promises", - "Version": "1.2.0.1", + "Version": "1.3.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R6", "Rcpp", + "fastmap", "later", "magrittr", "rlang", "stats" ], - "Hash": "4ab2c43adb4d4699cf3690acd378d75d" + "Hash": "434cd5388a3979e74be5c219bcd6e77d" }, "purrr": { "Package": "purrr", - "Version": "1.0.1", + "Version": "1.0.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1136,17 +1180,14 @@ "rlang", "vctrs" ], - "Hash": "d71c815267c640f17ddbf7f16144b4bb" + "Hash": "1cba04a4e9414bdefc9dcaa99649a8dc" }, "rapidoc": { "Package": "rapidoc", - "Version": "8.4.3", + "Version": "9.3.4", "Source": "Repository", "Repository": "CRAN", - "Requirements": [ - "jsonlite" - ], - "Hash": "576f303483fd25cda71f6c4e16682d1c" + "Hash": "bd71bc628219b96e96dd030f8c85691e" }, "rappdirs": { "Package": "rappdirs", @@ -1160,7 +1201,7 @@ }, "readr": { "Package": "readr", - "Version": "2.1.4", + "Version": "2.1.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1179,11 +1220,11 @@ "utils", "vroom" ], - "Hash": "b5047343b3825f37ad9d3b5d89aa1078" + "Hash": "9de96463d2117f6ac49980577939dfb3" }, "recipes": { "Package": "recipes", - "Version": "1.0.5", + "Version": "1.0.10", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1212,32 +1253,32 @@ "vctrs", "withr" ], - "Hash": "a3ad6802b18da51f9d38ac7ae8949166" + "Hash": "69783cdd607c58fffb21c5c26c6ededf" }, "renv": { "Package": "renv", - "Version": "0.17.0", + "Version": "1.0.7", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "utils" ], - "Hash": "ce3065fc1a0b64a859f55ac3998d6927" + "Hash": "397b7b2a265bc5a7a06852524dabae20" }, "rlang": { "Package": "rlang", - "Version": "1.0.6", + "Version": "1.1.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "utils" ], - "Hash": "4ed1f8336c8d52c3e750adcdc57228a7" + "Hash": "42548638fae05fd9a9b5f3f437fbbbe2" }, "rpart": { "Package": "rpart", - "Version": "4.1.19", + "Version": "4.1.23", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1246,36 +1287,51 @@ "graphics", "stats" ], - "Hash": "b3c892a81783376cc2204af0f5805a80" + "Hash": "b3d390424f41d04174cccf84d49676c2" }, "scales": { "Package": "scales", - "Version": "1.2.1", + "Version": "1.3.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "R6", "RColorBrewer", + "cli", "farver", + "glue", "labeling", "lifecycle", "munsell", "rlang", "viridisLite" ], - "Hash": "906cb23d2f1c5680b8ce439b44c6fa63" + "Hash": "c19df082ba346b0ffa6f833e92de34d1" + }, + "shape": { + "Package": "shape", + "Version": "1.4.6.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "stats" + ], + "Hash": "5c47e84dc0a3ca761ae1d307889e796d" }, "sodium": { "Package": "sodium", - "Version": "1.2.1", + "Version": "1.3.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "3606bb09e0914edd4fc8313b500dcd5e" + "Hash": "dd86d6fd2a01d4eb3777dfdee7076d56" }, "stringi": { "Package": "stringi", - "Version": "1.7.12", + "Version": "1.8.3", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1284,11 +1340,11 @@ "tools", "utils" ], - "Hash": "ca8bd84263c77310739d2cf64d84d7c9" + "Hash": "058aebddea264f4c99401515182e656a" }, "stringr": { "Package": "stringr", - "Version": "1.5.0", + "Version": "1.5.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1301,11 +1357,11 @@ "stringi", "vctrs" ], - "Hash": "671a4d384ae9d32fc47a14e98bfa3dc8" + "Hash": "960e2ae9e09656611e0b8214ad543207" }, "survival": { "Package": "survival", - "Version": "3.5-3", + "Version": "3.5-8", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1317,7 +1373,7 @@ "stats", "utils" ], - "Hash": "aea2b8787db7088ba50ba389848569ee" + "Hash": "184d7799bca4ba8c3be72ea396f4b9a3" }, "swagger": { "Package": "swagger", @@ -1328,14 +1384,14 @@ }, "sys": { "Package": "sys", - "Version": "3.4.1", + "Version": "3.4.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "34c16f1ef796057bfa06d3f4ff818a5d" + "Hash": "3a1be13d68d47a8cd0bfd74739ca1555" }, "tibble": { "Package": "tibble", - "Version": "3.1.8", + "Version": "3.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1350,11 +1406,11 @@ "utils", "vctrs" ], - "Hash": "56b6934ef0f8c68225949a8672fe1a8f" + "Hash": "a84e2cc86d07289b3b6f5069df7a004c" }, "tidyr": { "Package": "tidyr", - "Version": "1.3.0", + "Version": "1.3.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1373,11 +1429,11 @@ "utils", "vctrs" ], - "Hash": "e47debdc7ce599b070c8e78e8ac0cfcf" + "Hash": "915fb7ce036c22a6a33b5a8adb712eb1" }, "tidyselect": { "Package": "tidyselect", - "Version": "1.2.0", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1389,11 +1445,11 @@ "vctrs", "withr" ], - "Hash": "79540e5fcd9e0435af547d885f184fd5" + "Hash": "829f27b9c4919c16b593794a6344d6c0" }, "timeDate": { "Package": "timeDate", - "Version": "4022.108", + "Version": "4032.109", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1403,43 +1459,43 @@ "stats", "utils" ], - "Hash": "3f7918d2b36c17ffe07cddba6458453e" + "Hash": "fa276a2ec2555d74b4eabf56fba3d209" }, "timechange": { "Package": "timechange", - "Version": "0.2.0", + "Version": "0.3.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "cpp11" ], - "Hash": "8548b44f79a35ba1791308b61e6012d7" + "Hash": "c5f3c201b931cd6474d17d8700ccb1c8" }, "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", - "Version": "1.2.3", + "Version": "1.2.4", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "1fe17157424bb09c48a8b3b550c753bc" + "Hash": "62b65c52671e6665f803ff02954446e9" }, "vctrs": { "Package": "vctrs", - "Version": "0.5.2", + "Version": "0.6.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1449,18 +1505,20 @@ "lifecycle", "rlang" ], - "Hash": "e4ffa94ceed5f124d429a5a5f0f5b378" + "Hash": "c03fa420630029418f7e6da3667aac4a" }, "vetiver": { "Package": "vetiver", - "Version": "0.2.0", + "Version": "0.2.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "bundle", "butcher", + "cereal", "cli", + "ellipsis", "fs", "generics", "glue", @@ -1476,21 +1534,21 @@ "vctrs", "withr" ], - "Hash": "d65886d5900cc0260cedaf54b1bd13b3" + "Hash": "b9a6f592769dc2b70a0a7bd1478741f2" }, "viridisLite": { "Package": "viridisLite", - "Version": "0.4.1", + "Version": "0.4.2", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R" ], - "Hash": "62f4b5da3e08d8e5bcba6cac15603f70" + "Hash": "c826c7c4241b6fc89ff55aaea3fa7491" }, "vroom": { "Package": "vroom", - "Version": "1.6.1", + "Version": "1.6.5", "Source": "Repository", "Repository": "CRAN", "Requirements": [ @@ -1512,18 +1570,18 @@ "vctrs", "withr" ], - "Hash": "7015a74373b83ffaef64023f4a0f5033" + "Hash": "390f9315bc0025be03012054103d227c" }, "webutils": { "Package": "webutils", - "Version": "1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "curl", "jsonlite" ], - "Hash": "75d8b5b05fe22659b54076563f83f26a" + "Hash": "6a7f2a3084c7249d2f1466d6e4cc2e84" }, "whisker": { "Package": "whisker", @@ -1534,41 +1592,42 @@ }, "withr": { "Package": "withr", - "Version": "2.5.0", + "Version": "3.0.0", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", "grDevices", - "graphics", - "stats" + "graphics" ], - "Hash": "c0e49a9760983e81e55cdd9be92e7182" + "Hash": "d31b6c62c10dcf11ec530ca6b0dd5d35" }, "xml2": { "Package": "xml2", - "Version": "1.3.3", + "Version": "1.3.6", "Source": "Repository", "Repository": "CRAN", "Requirements": [ "R", - "methods" + "cli", + "methods", + "rlang" ], - "Hash": "40682ed6a969ea5abfd351eb67833adc" + "Hash": "1d0336142f4cd25d8d23cd3ba7a8fb61" }, "yaml": { "Package": "yaml", - "Version": "2.3.7", + "Version": "2.3.8", "Source": "Repository", "Repository": "CRAN", - "Hash": "0d0056cc5383fbc240ccd0cb584bf436" + "Hash": "29240487a071f535f5e5d5a323b7afbd" }, "zip": { "Package": "zip", - "Version": "2.2.2", + "Version": "2.3.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "c42bfcec3fa6a0cce17ce1f8bc684f88" + "Hash": "fcc4bd8e6da2d2011eb64a5e5cc685ab" } } } diff --git a/renv/.gitignore b/renv/.gitignore index bed446c..0ec0cbb 100644 --- a/renv/.gitignore +++ b/renv/.gitignore @@ -1,7 +1,7 @@ -sandbox/ +library/ local/ cellar/ -library/ lock/ python/ +sandbox/ staging/ diff --git a/renv/activate.R b/renv/activate.R index 360dd52..d13f993 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,10 +2,28 @@ local({ # the requested version of renv - version <- "0.17.0" + version <- "1.0.7" + attr(version, "sha") <- NULL # the project directory - project <- getwd() + project <- Sys.getenv("RENV_PROJECT") + if (!nzchar(project)) + project <- getwd() + + # use start-up diagnostics if enabled + diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE") + if (diagnostics) { + start <- Sys.time() + profile <- tempfile("renv-startup-", fileext = ".Rprof") + utils::Rprof(profile) + on.exit({ + utils::Rprof(NULL) + elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L) + writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed))) + writeLines(sprintf("- Profile: %s", profile)) + print(utils::summaryRprof(profile)) + }, add = TRUE) + } # figure out whether the autoloader is enabled enabled <- local({ @@ -15,6 +33,14 @@ local({ if (!is.null(override)) return(override) + # if we're being run in a context where R_LIBS is already set, + # don't load -- presumably we're being run as a sub-process and + # the parent process has already set up library paths for us + rcmd <- Sys.getenv("R_CMD", unset = NA) + rlibs <- Sys.getenv("R_LIBS", unset = NA) + if (!is.na(rlibs) && !is.na(rcmd)) + return(FALSE) + # next, check environment variables # TODO: prefer using the configuration one in the future envvars <- c( @@ -34,9 +60,22 @@ local({ }) - if (!enabled) + # bail if we're not enabled + if (!enabled) { + + # if we're not enabled, we might still need to manually load + # the user profile here + profile <- Sys.getenv("R_PROFILE_USER", unset = "~/.Rprofile") + if (file.exists(profile)) { + cfg <- Sys.getenv("RENV_CONFIG_USER_PROFILE", unset = "TRUE") + if (tolower(cfg) %in% c("true", "t", "1")) + sys.source(profile, envir = globalenv()) + } + return(FALSE) + } + # avoid recursion if (identical(getOption("renv.autoloader.running"), TRUE)) { warning("ignoring recursive attempt to run renv autoloader") @@ -60,21 +99,90 @@ 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) + + } + + heredoc <- function(text, leave = 0) { + + # remove leading, trailing whitespace + trimmed <- gsub("^\\s*\\n|\\n\\s*$", "", text) + + # split into lines + lines <- strsplit(trimmed, "\n", fixed = TRUE)[[1L]] + + # compute common indent + indent <- regexpr("[^[:space:]]", lines) + common <- min(setdiff(indent, -1L)) - leave + paste(substring(lines, common), collapse = "\n") + + } + + 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,31 +191,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()) { - repos <- getOption("renv.tests.repos") - if (!is.null(repos)) - return(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") @@ -146,33 +255,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") } @@ -236,8 +346,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" @@ -254,13 +362,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 } @@ -317,8 +422,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( @@ -326,14 +429,11 @@ local({ condition = identity ) - if (identical(status, 0L)) { - message("OK") + if (identical(status, 0L)) return(destfile) - } } - message("FAILED") return(FALSE) } @@ -356,7 +456,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) @@ -365,10 +465,7 @@ local({ } - fmt <- "* Bootstrapping with tarball at path '%s'." - msg <- sprintf(fmt, tarball) - message(msg) - + catf("- Using local tarball '%s'.", tarball) tarball } @@ -395,8 +492,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) @@ -406,26 +501,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", @@ -433,19 +607,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) } @@ -486,6 +648,9 @@ local({ # if the user has requested an automatic prefix, generate it auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) + if (is.na(auto) && getRversion() >= "4.4.0") + auto <- "TRUE" + if (auto %in% c("TRUE", "True", "true", "1")) return(renv_bootstrap_platform_prefix_auto()) @@ -655,34 +820,61 @@ local({ } - renv_bootstrap_validate_version <- function(version) { + renv_bootstrap_validate_version <- function(version, description = NULL) { - loadedversion <- utils::packageDescription("renv", fields = "Version") - if (version == loadedversion) + # 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") + + # 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 + renv_bootstrap_validate_version_release(version, description) + + if (valid) return(TRUE) - # 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 = "@") + # the loaded version of renv doesn't match the requested version; + # give the user instructions on how to proceed + dev <- identical(description[["RemoteType"]], "github") + remote <- if (dev) + paste("rstudio/renv", description[["RemoteSha"]], sep = "@") else - paste("renv", loadedversion, sep = "@") + paste("renv", description[["Version"]], sep = "@") - 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.", - sep = "\n" + # display both loaded version + sha if available + friendly <- renv_bootstrap_version_friendly( + version = description[["Version"]], + sha = if (dev) description[["RemoteSha"]] ) - msg <- sprintf(fmt, loadedversion, version, remote) - warning(msg, call. = FALSE) + fmt <- heredoc(" + 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. + ") + 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-") @@ -706,7 +898,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) @@ -847,6 +1039,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) { @@ -855,7 +1081,7 @@ local({ # if jsonlite is loaded, use that instead if ("jsonlite" %in% loadedNamespaces()) { - json <- catch(renv_json_read_jsonlite(file, text)) + json <- tryCatch(renv_json_read_jsonlite(file, text), error = identity) if (!inherits(json, "error")) return(json) @@ -864,7 +1090,7 @@ local({ } # otherwise, fall back to the default JSON reader - json <- catch(renv_json_read_default(file, text)) + json <- tryCatch(renv_json_read_default(file, text), error = identity) if (!inherits(json, "error")) return(json) @@ -877,14 +1103,14 @@ local({ } renv_json_read_jsonlite <- function(file = NULL, text = NULL) { - text <- paste(text %||% read(file), collapse = "\n") + text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n") jsonlite::fromJSON(txt = text, simplifyVector = FALSE) } renv_json_read_default <- function(file = NULL, text = NULL) { # find strings in the JSON - text <- paste(text %||% read(file), collapse = "\n") + text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n") pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' locs <- gregexpr(pattern, text, perl = TRUE)[[1]] @@ -932,14 +1158,14 @@ local({ map <- as.list(map) # remap strings in object - remapped <- renv_json_remap(json, map) + remapped <- renv_json_read_remap(json, map) # evaluate eval(remapped, envir = baseenv()) } - renv_json_remap <- function(json, map) { + renv_json_read_remap <- function(json, map) { # fix names if (!is.null(names(json))) { @@ -966,7 +1192,7 @@ local({ # recurse if (is.recursive(json)) { for (i in seq_along(json)) { - json[i] <- list(renv_json_remap(json[[i]], map)) + json[i] <- list(renv_json_read_remap(json[[i]], map)) } } @@ -986,35 +1212,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 f8a5c7c..0000000 --- a/renv/settings.dcf +++ /dev/null @@ -1,7 +0,0 @@ -external.libraries: -ignored.packages: -package.dependency.fields: Imports, Depends, LinkingTo -r.version: -snapshot.type: implicit -use.cache: TRUE -vcs.ignore.library: TRUE