Skip to content

Instantly share code, notes, and snippets.

@philipp-baumann
Created October 7, 2019 17:28
Show Gist options
  • Save philipp-baumann/7be8512e7504c387f41f26da46546488 to your computer and use it in GitHub Desktop.
Save philipp-baumann/7be8512e7504c387f41f26da46546488 to your computer and use it in GitHub Desktop.
Plan and build targets
## Load packages
pkgs <- c("here", "drake", "tidyverse", "data.table",
"simplerspec", "caret", "Cubist", "rsample", "nls.multstart",
"broom", # modeling
"future", "future.apply", "doParallel", "doFuture", # asynchronous computation
"gghighlight", "grid", "gridExtra", "cowplot", # graphics
"xtable") # tables
purrr::walk(pkgs, library, character.only = TRUE)
funs <- list(
here("R","resampling-cubist-rules.R"),
here("R", "misc.R"),
here("R", "nls-wrappers.R")
)
walk(funs, source)
## Scripts to run
scripts <- c(
"10_read-transform-data.R",
"20_summarize-data.R",
"31_model-water-content-nested.R",
"40_model-swr-curve.R",
"51_model-available-water-a-b-d-nested.R",
"52_model-available-water-a-b-d-nested-cavg.R",
"61_model-swr-params-vm-c.R",
"62_model-swr-params-cavg-vm-c.R",
"70_collect-swr-params.R",
"71_collect-swr-params-cavg.R",
"81_compare-available-water-a-b-c-d-nested.R",
"82_compare-available-water-a-b-c-d-nested-cavg.R"
)
## Convert code in scripts to plan
plans <- map(set_names(scripts), code_to_plan)
## Set up future resolving strategies ==========================================
# plan(future.callr::callr, workers = future::availableCores() - 1)
plan(multiprocess)
## Finalize into one master drake plan =========================================
# Combine multiple plans into one
plan <- bind_rows(
plans
)
## Make configuration ==========================================================
config <- drake_config(plan)
outdated(config)
## Build targets (R objects) listed in plan ====================================
# Record start time
start_time <- Sys.time()
make(plan, lock_envir = FALSE)
end_time <- Sys.time()
exec_time <- end_time - start_time
# Predict runtime to rebuild the entire drake cache
predict_runtime(config, from_scratch = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment