Unitar allows you to load targets from external projects. This is useful for sharing targets across projects. One specific use case is if you have some general-purpose data resources that you use frequently in many projects. Using unitar, you can create a single "resources" project, and then use those resources repeatedly. This repository provides a demo for this kind of resources project.
In addition to its target sharing functions, unitar also provides a target factory that makes it easy to populate a targets project by specifying target parameters in a csv file.
In this project, the list of resource targets are defined in the included targets_list.csv. In _targets.R, we use unitar::build_pep_resource_targets to convert this csv into targets.
This resource repository can then be used as a normal targets project:
library("targets")
tar_make()
tar_meta()
tar_load("file1")
file1
Like any normal targets project, this project can also now be used as an external targets project using unitar:
library("unitar")
options(tar_dirs=c("/home/nsheff/code/unitar_resources_demo"))
unitar_meta()
unitar_load("file1")
file1
Now, you can use these just as any of the modes defined in the unitar documentation. One common mode would be to use these resources to create derived resources or analysis in your more specialized targets project, and you want to track the resources so you can update things if they change, but you don't want to duplicate the caches into your local folder because they're large. Todo that, you'd do something like:
# _targets.R
library("unitar")
options(tar_dirs=c("/home/nsheff/code/unitar_resources_demo"))
local_filter_big_reference_data = function(big_data_set_path) {
big_data_set = unitar_read_from_path(big_data_set_path)
big_data_set[big_data_set > 2]
}
list(
tar_target(
big_data_set_path,
unitar_path("file1"),
format = "file"
),
tar_target(
filtered_data_set,
local_filter_big_reference_data(big_data_set_path)
)
)
The targets list is a PEP. Each target is a row in targets_list.csv. The columns are:
sample_name: target nametype: Specifyfileif the target is a file load, orcallif it's a function callfunction: this is the function to call (or to read the file, for file targets)description: ignored by the software, just for your informationlocal_path: For targets of typefile, specify the path to the file
For targets of type call, you may specify parameters to the function in the target_params.csv file. In this table, each row is a function parameter. You must specify 3 columns:
sample_name: target name, which must match the value in thetargets_list.csvfile.arg: argument name, as assigned by your function signatureval: value to pass for that argument.