generated from ecohealthalliance/container-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use capsule for easier renv management - Create a separate sandbox targets project - Load multiple .env files - Use .env_user for setting USE_CAPSULE and TAR_PROJECT) - .gitignore stuff appropriately to retain outputs and keep meta files - Add all_targets() convenience function
- Loading branch information
Noam Ross
committed
Aug 11, 2023
1 parent
dea82d2
commit 0b7abee
Showing
6 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#' Collect all targets and lists of targets in the environment | ||
all_targets <- function(env = parent.env(environment()), type = "tar_target") { | ||
rfn <- function(obj) inherits(obj, type) || (is.list(obj) && all(vapply(obj, rfn, logical(1)))) | ||
objs <- ls(env) | ||
out <- list() | ||
for(o in objs) { | ||
obj <- get(o, envir = env) | ||
if (rfn(obj)) { | ||
out[[length(out) + 1]] <- obj | ||
} | ||
} | ||
return(out) | ||
} | ||
|
||
# TODO: convenience functions for reading targets from S3 | ||
# Need to figure out the best way for these to work with both regular and | ||
# file-type targets, which should emerge from working with them in the sandbox | ||
# tar_read_s3 <- function(target_name, bucket = Sys.getenv("AWS_BUCKET_ID"), | ||
# prefix = "_targets") { | ||
# ## if target_name does not exist, convert the symbol to character | ||
# if (!exists(target_name)) { | ||
# target_name <- as.character(substitute(target_name)) | ||
# } | ||
# | ||
# } | ||
# | ||
# tar_load_s3 <- function(target_name, ...) { | ||
# | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Re-record current dependencies for CAPSULE users | ||
if(Sys.getenv("USE_CAPSULE") %in% c("1", "TRUE", "true")) | ||
capsule::capshot(c("packages.R", | ||
list.files(pattern = "_targets.*\\.(r|R)$", full.names = TRUE), | ||
list.files("R", pattern = "\\.(R|r)$", full.names = TRUE))) | ||
|
||
# Load packages (in packages.R) and load project-specific functions in R folder | ||
suppressPackageStartupMessages(source("packages.R")) | ||
for (f in list.files(here::here("R"), full.names = TRUE)) source (f) | ||
|
||
|
||
|
||
all_targets() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
main: | ||
store: _targets | ||
script: _targets.R | ||
sandbox: | ||
store: _targets_sandbox | ||
script: _targets_sandbox.R |