| Title: | Make Your 'targets' Pipelines into a Package |
|---|---|
| Description: | Runs 'targets' pipelines bundled inside a package and caches the results in the R user cache directory, so that users of the package do not need to rerun the pipeline themselves. Package authors can update the cached results at any time by releasing a new package version. |
| Authors: | Mizuki Uchida [aut, cre, cph] (ORCID: <https://orcid.org/0009-0003-6534-6942>) |
| Maintainer: | Mizuki Uchida <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-07-12 14:19:11 UTC |
| Source: | https://github.com/cran/tarchives |
Function factory for archived targets
tar_archive( f, package, pipeline, envir = parent.frame(), script = targets::tar_config_get("script"), store = targets::tar_config_get("store") )tar_archive( f, package, pipeline, envir = parent.frame(), script = targets::tar_config_get("script"), store = targets::tar_config_get("store") )
f |
A function of targets package. |
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
envir |
An environment, where to run the target R script
(default: The |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
A function.
tar_outdated_archive <- tar_archive( targets::tar_outdated, package = "tarchives", pipeline = "example-model" ) withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), tar_outdated_archive() )tar_outdated_archive <- tar_archive( targets::tar_outdated, package = "tarchives", pipeline = "example-model" ) withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), tar_outdated_archive() )
Returns the names of the pipelines bundled in a package's
inst/tarchives directory. Use it to discover which pipelines are
available before running them with tar_make_archive() or inspecting their
targets with tar_manifest_archive().
tar_archive_pipelines( package, envir = parent.frame(), script = targets::tar_config_get("script") )tar_archive_pipelines( package, envir = parent.frame(), script = targets::tar_config_get("script") )
package |
A scalar character of the package name. |
envir |
An environment used to resolve |
script |
Character of length 1, path to the
target script file. Defaults to |
A character vector of pipeline names. A pipeline is a directory in
inst/tarchives that contains a target script file (script), so the
shared R/ helper directory is not included.
tar_manifest_archive() to list the targets within a pipeline.
tar_archive_pipelines(package = "tarchives")tar_archive_pipelines(package = "tarchives")
Path to the archived target script file
tar_archive_script( package, pipeline, envir = parent.frame(), script = targets::tar_config_get("script") )tar_archive_script( package, pipeline, envir = parent.frame(), script = targets::tar_config_get("script") )
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
envir |
An environment used to resolve |
script |
Character of length 1, path to the
target script file. Defaults to |
A scalar character of the path to the archived target script file.
tar_archive_script(package = "tarchives", pipeline = "example-model")tar_archive_script(package = "tarchives", pipeline = "example-model")
Path to the archived target store directory
tar_archive_store(package, pipeline, store = targets::tar_config_get("store"))tar_archive_store(package, pipeline, store = targets::tar_config_get("store"))
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
store |
Character of length 1, path to the
|
A scalar character of the path to the archived target store directory.
tar_archive_store(package = "tarchives", pipeline = "example-model")tar_archive_store(package = "tarchives", pipeline = "example-model")
tarchives version of targets::tar_destroy(). Removes the cached targets
store of an archived pipeline from the R user cache directory
(tools::R_user_dir("tarchives", "cache")).
tar_destroy_archive( package, pipeline, destroy = "all", batch_size = 1000L, verbose = TRUE, ask = NULL, store = targets::tar_config_get("store") )tar_destroy_archive( package, pipeline, destroy = "all", batch_size = 1000L, verbose = TRUE, ask = NULL, store = targets::tar_config_get("store") )
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
destroy |
Character of length 1, what to destroy. Choices:
|
batch_size |
Positive integer between 1 and 1000, number of target definition objects to delete from the cloud with each HTTP API request. Currently only supported for AWS. Cannot be more than 1000. |
verbose |
Logical of length 1, whether to print console messages to show progress when deleting each batch of targets from each cloud bucket. Batched deletion with verbosity is currently only supported for AWS. |
ask |
Logical of length 1, whether to pause with a menu prompt
before deleting files. To disable this menu, set the |
store |
Character of length 1, path to the
|
NULL (invisibly).
withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_destroy_archive(package = "tarchives", pipeline = "example-model", ask = FALSE) } )withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_destroy_archive(package = "tarchives", pipeline = "example-model", ask = FALSE) } )
tarchives version of targets::tar_load(). Reads one or more targets from
an archived pipeline's store and assigns them into an environment.
tar_load_archive( names, package, pipeline, branches = NULL, meta = NULL, strict = TRUE, silent = FALSE, envir = parent.frame(), store = targets::tar_config_get("store") )tar_load_archive( names, package, pipeline, branches = NULL, meta = NULL, strict = TRUE, silent = FALSE, envir = parent.frame(), store = targets::tar_config_get("store") )
names |
Names of the targets to load.
The object supplied to |
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
branches |
Integer of indices of the branches to load for any targets that are patterns. |
meta |
Data frame of target metadata from |
strict |
Logical of length 1, whether to error out
if one of the selected targets is in the metadata
but cannot be loaded.
Set to |
silent |
Logical of length 1. Only relevant when
|
envir |
R environment in which to load target return values. |
store |
Character of length 1, directory path to the data store of the pipeline. |
Nothing.
withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_load_archive(model, package = "tarchives", pipeline = "example-model") model } )withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_load_archive(model, package = "tarchives", pipeline = "example-model") model } )
Run an archived pipeline of targets
tar_make_archive( package, pipeline, names = NULL, shortcut = targets::tar_config_get("shortcut"), reporter = "silent", seconds_meta_append = targets::tar_config_get("seconds_meta_append"), seconds_meta_upload = targets::tar_config_get("seconds_meta_upload"), seconds_reporter = targets::tar_config_get("seconds_reporter"), seconds_interval = targets::tar_config_get("seconds_interval"), callr_function = callr::r, callr_arguments = targets::tar_callr_args_default(callr_function, reporter), envir = parent.frame(), script = targets::tar_config_get("script"), store = targets::tar_config_get("store"), garbage_collection = NULL, use_crew = targets::tar_config_get("use_crew"), terminate_controller = TRUE, as_job = targets::tar_config_get("as_job") )tar_make_archive( package, pipeline, names = NULL, shortcut = targets::tar_config_get("shortcut"), reporter = "silent", seconds_meta_append = targets::tar_config_get("seconds_meta_append"), seconds_meta_upload = targets::tar_config_get("seconds_meta_upload"), seconds_reporter = targets::tar_config_get("seconds_reporter"), seconds_interval = targets::tar_config_get("seconds_interval"), callr_function = callr::r, callr_arguments = targets::tar_callr_args_default(callr_function, reporter), envir = parent.frame(), script = targets::tar_config_get("script"), store = targets::tar_config_get("store"), garbage_collection = NULL, use_crew = targets::tar_config_get("use_crew"), terminate_controller = TRUE, as_job = targets::tar_config_get("as_job") )
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
names |
Names of the targets to run or check. Set to |
shortcut |
Logical of length 1, how to interpret the |
reporter |
A scalar character of the reporter type. By default,
|
seconds_meta_append |
Positive numeric of length 1 with the minimum
number of seconds between saves to the local metadata and progress files
in the data store.
his is an aggressive optimization setting not recommended
for most users:
higher values generally make the pipeline run faster, but unsaved
work (in the event of a crash) is not up to date.
When the pipeline ends,
all the metadata and progress data is saved immediately,
regardless of When the pipeline is just skipping targets, the actual interval
between saves is |
seconds_meta_upload |
Positive numeric of length 1 with the minimum
number of seconds between uploads of the metadata and progress data
to the cloud
(see https://books.ropensci.org/targets/cloud-storage.html).
Higher values generally make the pipeline run faster, but unsaved
work (in the event of a crash) may not be backed up to the cloud.
When the pipeline ends,
all the metadata and progress data is uploaded immediately,
regardless of |
seconds_reporter |
Deprecated on 2025-03-31
( |
seconds_interval |
Deprecated on 2023-08-24
(targets version 1.2.2.9001).
Use |
callr_function |
A function from |
callr_arguments |
A list of arguments to |
envir |
An environment, where to run the target R script
(default: The |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
garbage_collection |
Deprecated. Use the |
use_crew |
Logical of length 1, whether to use |
terminate_controller |
Logical of length 1. For a |
as_job |
|
NULL except if callr_function = callr::r_bg(), in which case
a handle to the callr background process is returned. Either way,
the value is invisibly returned.
withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), tar_make_archive(package = "tarchives", pipeline = "example-model") )withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), tar_make_archive(package = "tarchives", pipeline = "example-model") )
tarchives version of targets::tar_manifest(). Returns a data frame of the
targets defined in an archived pipeline's target script file.
tar_manifest_archive( package, pipeline, names = NULL, fields = NULL, drop_missing = TRUE, callr_function = callr::r, callr_arguments = targets::tar_callr_args_default(callr_function), envir = parent.frame(), script = targets::tar_config_get("script") )tar_manifest_archive( package, pipeline, names = NULL, fields = NULL, drop_missing = TRUE, callr_function = callr::r, callr_arguments = targets::tar_callr_args_default(callr_function), envir = parent.frame(), script = targets::tar_config_get("script") )
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
names |
Names of the targets to show. Set to |
fields |
Names of the fields, or columns, to show. Set to
|
drop_missing |
Logical of length 1, whether to automatically omit empty columns and columns with all missing values. |
callr_function |
A function from |
callr_arguments |
A list of arguments to |
envir |
An environment, where to run the target R script
(default: The |
script |
Character of length 1, path to the
target script file. Defaults to |
A data frame of information about the targets in the pipeline. Rows appear in topological order (the order they will run without any influence from parallel computing or priorities).
tar_archive_pipelines() to list the pipelines in a package.
withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), tar_manifest_archive(package = "tarchives", pipeline = "example-model") )withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), tar_manifest_archive(package = "tarchives", pipeline = "example-model") )
tarchives version of targets::tar_meta(). Returns the metadata of an
archived pipeline's store.
tar_meta_archive( package, pipeline, names = NULL, fields = NULL, targets_only = FALSE, complete_only = FALSE, store = targets::tar_config_get("store") )tar_meta_archive( package, pipeline, names = NULL, fields = NULL, targets_only = FALSE, complete_only = FALSE, store = targets::tar_config_get("store") )
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
names |
Optional, names of the targets. If supplied, |
fields |
Optional, names of columns/fields to select. If supplied,
|
targets_only |
Logical, whether to just show information about targets or also return metadata on functions and other global objects. |
complete_only |
Logical, whether to return only complete rows
(no |
store |
Character of length 1, path to the
|
A data frame with one row per target/object and the selected fields.
withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_meta_archive(package = "tarchives", pipeline = "example-model") } )withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_meta_archive(package = "tarchives", pipeline = "example-model") } )
Read a target's value from archive storage
tar_read_archive( name, package, pipeline, branches = NULL, meta = NULL, store = targets::tar_config_get("store") ) tar_read_archive_raw( name, package, pipeline, branches = NULL, meta = NULL, store = targets::tar_config_get("store") )tar_read_archive( name, package, pipeline, branches = NULL, meta = NULL, store = targets::tar_config_get("store") ) tar_read_archive_raw( name, package, pipeline, branches = NULL, meta = NULL, store = targets::tar_config_get("store") )
name |
Name of the target to read.
|
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
branches |
Integer of indices of the branches to load if the target is a pattern. |
meta |
Data frame of metadata from |
store |
Character of length 1, path to the
|
tar_read_archive() captures name with non-standard evaluation, whereas
tar_read_archive_raw() takes it as a character string.
The target's return value from its file in
_targets/objects/, or the paths to the custom files and directories
if format = "file" was set.
withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_read_archive(model, package = "tarchives", pipeline = "example-model") } )withr::with_envvar( c(R_USER_CACHE_DIR = tempfile()), { tar_make_archive(package = "tarchives", pipeline = "example-model") tar_read_archive(model, package = "tarchives", pipeline = "example-model") } )
Run archived R scripts
tar_source_archive( package, files = "R", envir = targets::tar_option_get("envir"), change_directory = FALSE )tar_source_archive( package, files = "R", envir = targets::tar_option_get("envir"), change_directory = FALSE )
package |
A scalar character of the package name. |
files |
Character vector of file and directory paths to look for R scripts to run. Paths must either be absolute paths or must be relative to the current working directory just before the function call. |
envir |
Environment to run the scripts. Defaults to
|
change_directory |
Logical, whether to temporarily change the working directory to the directory of each R script before running it. |
NULL (invisibly)
tar_source_archive(package = "tarchives")tar_source_archive(package = "tarchives")
Declare a target to read an archive
tar_target_archive( name, package, pipeline, name_archive = NULL, ..., pattern = NULL, packages = targets::tar_option_get("packages"), library = targets::tar_option_get("library"), deps = NULL, string = NULL, format = targets::tar_option_get("format"), repository = targets::tar_option_get("repository"), iteration = targets::tar_option_get("iteration"), error = targets::tar_option_get("error"), memory = targets::tar_option_get("memory"), garbage_collection = isTRUE(targets::tar_option_get("garbage_collection")), deployment = targets::tar_option_get("deployment"), priority = targets::tar_option_get("priority"), resources = targets::tar_option_get("resources"), storage = targets::tar_option_get("storage"), retrieval = targets::tar_option_get("retrieval"), cue = targets::tar_option_get("cue"), description = targets::tar_option_get("description") ) tar_target_archive_raw( name, package, pipeline, name_archive = name, ..., pattern = NULL, packages = targets::tar_option_get("packages"), library = targets::tar_option_get("library"), deps = NULL, string = NULL, format = targets::tar_option_get("format"), repository = targets::tar_option_get("repository"), iteration = targets::tar_option_get("iteration"), error = targets::tar_option_get("error"), memory = targets::tar_option_get("memory"), garbage_collection = isTRUE(targets::tar_option_get("garbage_collection")), deployment = targets::tar_option_get("deployment"), priority = targets::tar_option_get("priority"), resources = targets::tar_option_get("resources"), storage = targets::tar_option_get("storage"), retrieval = targets::tar_option_get("retrieval"), cue = targets::tar_option_get("cue"), description = targets::tar_option_get("description") )tar_target_archive( name, package, pipeline, name_archive = NULL, ..., pattern = NULL, packages = targets::tar_option_get("packages"), library = targets::tar_option_get("library"), deps = NULL, string = NULL, format = targets::tar_option_get("format"), repository = targets::tar_option_get("repository"), iteration = targets::tar_option_get("iteration"), error = targets::tar_option_get("error"), memory = targets::tar_option_get("memory"), garbage_collection = isTRUE(targets::tar_option_get("garbage_collection")), deployment = targets::tar_option_get("deployment"), priority = targets::tar_option_get("priority"), resources = targets::tar_option_get("resources"), storage = targets::tar_option_get("storage"), retrieval = targets::tar_option_get("retrieval"), cue = targets::tar_option_get("cue"), description = targets::tar_option_get("description") ) tar_target_archive_raw( name, package, pipeline, name_archive = name, ..., pattern = NULL, packages = targets::tar_option_get("packages"), library = targets::tar_option_get("library"), deps = NULL, string = NULL, format = targets::tar_option_get("format"), repository = targets::tar_option_get("repository"), iteration = targets::tar_option_get("iteration"), error = targets::tar_option_get("error"), memory = targets::tar_option_get("memory"), garbage_collection = isTRUE(targets::tar_option_get("garbage_collection")), deployment = targets::tar_option_get("deployment"), priority = targets::tar_option_get("priority"), resources = targets::tar_option_get("resources"), storage = targets::tar_option_get("storage"), retrieval = targets::tar_option_get("retrieval"), cue = targets::tar_option_get("cue"), description = targets::tar_option_get("description") )
name |
Symbol, name of the target.
In A target name must be a valid name for a symbol in R, and it
must not start with a dot. Subsequent targets
can refer to this name symbolically to induce a dependency relationship:
e.g. In most cases, The target name is the name of its local data file in storage. Some file systems are not case sensitive, which means converting a name to a different case may overwrite a different target. Please ensure all target names have unique names when converted to lower case. In addition, a target's
name determines its random number generator seed. In this way,
each target runs with a reproducible seed so someone else
running the same pipeline should get the same results,
and no two targets in the same pipeline share the same seed.
(Even dynamic branches have different names and thus different seeds.)
You can recover the seed of a completed target
with |
package |
A scalar character of the package name. |
pipeline |
A scalar character of the pipeline name. |
name_archive |
Symbol, name of the archived target. If |
... |
Arguments to pass to |
pattern |
Code to define a dynamic branching branching for a target.
In To demonstrate dynamic branching patterns, suppose we have
a pipeline with numeric vector targets |
packages |
Character vector of packages to load right before
the target runs or the output data is reloaded for
downstream targets. Use |
library |
Character vector of library paths to try
when loading |
deps |
Optional character vector of the adjacent upstream
dependencies of the target, including targets and global objects.
If |
string |
Optional string representation of the command.
Internally, the string gets hashed to check if the command changed
since last run, which helps |
format |
Optional storage format for the target's return value.
With the exception of |
repository |
Character of length 1, remote repository for target storage. Choices:
Note: if |
iteration |
Character of length 1, name of the iteration mode of the target. Choices:
|
error |
Character of length 1, what to do if the target stops and throws an error. Options:
|
memory |
Character of length 1, memory strategy. Possible values:
For cloud-based file targets
(e.g. |
garbage_collection |
Logical: |
deployment |
Character of length 1. If |
priority |
Deprecated on 2025-04-08 ( |
resources |
Object returned by |
storage |
Character string to control when the output of the target
is saved to storage. Only relevant when using
|
retrieval |
Character string to control when the current target
loads its dependencies into memory before running.
(Here, a "dependency" is another target upstream that the current one
depends on.) Only relevant when using
|
cue |
An optional object from |
description |
Character of length 1, a custom free-form human-readable
text description of the target. Descriptions appear as target labels
in functions like |
tar_target_archive() captures name and name_archive with non-standard
evaluation, whereas tar_target_archive_raw() takes them as character
strings.
The archive is built (if outdated) and read when the target runs, not when
the target script is sourced, so inspecting the pipeline with
targets::tar_manifest() or targets::tar_visnetwork() does not trigger a
build. The target tracks the installed version of package, so it reruns
and refreshes the data when a new version of the package providing the
archive is installed, and is skipped otherwise. Downstream targets still
only rebuild when the value actually changes.
A target definition object. Users should not modify these directly,
just feed them to list() in your target script file
(default: _targets.R).
tar_target_archive( model, package = "tarchives", pipeline = "example-model" )tar_target_archive( model, package = "tarchives", pipeline = "example-model" )
Set up tarchives for an existing package.
use_tarchives(store = targets::tar_config_get("store"))use_tarchives(store = targets::tar_config_get("store"))
store |
Character of length 1, path to the
|
No return value, called for side effects.
withr::with_tempdir( use_tarchives() )withr::with_tempdir( use_tarchives() )