-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from OxfordIHTM/dev
update targets template
- Loading branch information
Showing
7 changed files
with
176 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.RData | ||
.Ruserdata | ||
_targets | ||
docs |
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,34 @@ | ||
#' | ||
#' Collect all targets and lists of targets in the environment | ||
#' | ||
#' | ||
all_targets <- function(env = parent.env(environment()), | ||
type = "tar_target", | ||
add_list_names = TRUE) { | ||
|
||
## Function to determine if an object is a type (a target), | ||
## or a list on only that type | ||
rfn <- function(obj) | ||
inherits(obj, type) || (is.list(obj) && all(vapply(obj, rfn, logical(1)))) | ||
|
||
## Get the names of everything in the environment | ||
## (e.g. sourced in the _targets.R file) | ||
objs <- ls(env) | ||
|
||
out <- list() | ||
for (o in objs) { | ||
obj <- get(o, envir = env) ## Get each top-level object in turn | ||
if (rfn(obj)) { ## For targets and lists of targets | ||
out[[length(out) + 1]] <- obj ## Add them to the output | ||
|
||
## If the object is a list of targets, add a vector of the target names | ||
## to the environment So that one can call `tar_make(list_name)` to make | ||
## all the targets in that list | ||
if (add_list_names && is.list(obj)) { | ||
target_names <- vapply(obj, \(x) x$settings$name, character(1)) | ||
assign(o, target_names, envir = env) | ||
} | ||
} | ||
} | ||
return(out) | ||
} |
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
Empty file.