Title: | Dynamic Function-Oriented 'Make'-Like Declarative Pipelines |
Description: | Pipeline tools coordinate the pieces of computationally demanding analysis projects. The 'targets' package is a 'Make'-like pipeline tool for statistics and data science in R. The package skips costly runtime for tasks that are already up to date, orchestrates the necessary computation with implicit parallel computing, and abstracts files as R objects. If all the current output matches the current upstream code and data, then the whole pipeline is up to date, and the results are more trustworthy than otherwise. The methodology in this package borrows from GNU 'Make' (2015, ISBN:978-9881443519) and 'drake' (2018, <doi:10.21105/joss.00550>). |
Version: | 1.11.3 |
License: | MIT + file LICENSE |
URL: | https://docs.ropensci.org/targets/, https://github.com/ropensci/targets |
BugReports: | https://github.com/ropensci/targets/issues |
Depends: | R (≥ 3.5.0) |
Imports: | base64url (≥ 1.4), callr (≥ 3.7.0), cli (≥ 2.0.2), codetools (≥ 0.2.16), data.table (≥ 1.12.8), igraph (≥ 2.0.0), knitr (≥ 1.34), prettyunits (≥ 1.1.0), ps (≥ 1.8.0), R6 (≥ 2.4.1), rlang (≥ 1.0.0), secretbase (≥ 0.5.0), stats, tibble (≥ 3.0.1), tidyselect (≥ 1.1.0), tools, utils, vctrs (≥ 0.2.4), yaml (≥ 2.2.1) |
Suggests: | autometric (≥ 0.1.0), bslib, clustermq (≥ 0.9.2), crew (≥ 0.9.0), curl (≥ 4.3), DT (≥ 0.14), dplyr (≥ 1.0.0), fst (≥ 0.9.2), future (≥ 1.19.1), future.batchtools (≥ 0.9.0), future.callr (≥ 0.6.0), gargle (≥ 1.2.0), googleCloudStorageR (≥ 0.7.0), gt (≥ 0.2.2), keras (≥ 2.2.5.0), markdown (≥ 1.1), nanonext (≥ 0.12.0), rmarkdown (≥ 2.4), parallelly (≥ 1.35.0), paws.common (≥ 0.6.4), paws.storage (≥ 0.4.0), pkgload (≥ 1.1.0), processx (≥ 3.4.3), qs2, reprex (≥ 2.0.0), rstudioapi (≥ 0.11), R.utils (≥ 2.6.0), shiny (≥ 1.5.0), shinybusy (≥ 0.2.2), shinyWidgets (≥ 0.5.4), tarchetypes, testthat (≥ 3.0.0), torch (≥ 0.1.0), usethis (≥ 1.6.3), visNetwork (≥ 2.1.2) |
Encoding: | UTF-8 |
Language: | en-US |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-05-08 16:59:05 UTC; C240390 |
Author: | William Michael Landau
|
Maintainer: | William Michael Landau <will.landau.oss@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-05-08 17:40:02 UTC |
targets: Dynamic Function-Oriented Make-Like Declarative Pipelines for R
Description
A pipeline toolkit for Statistics and data science in R,
the targets
package brings function-oriented programming to
Make-like declarative pipelines. targets
orchestrates a pipeline
as a graph of dependencies,
skips steps that are already up to date, runs the necessary
computations with optional parallel workers, abstracts files as
R objects, and provides tangible evidence that the results are
reproducible given the underlying code and data.
The methodology in this package
borrows from GNU Make (2015, ISBN:978-9881443519)
and drake
(2018, doi:10.21105/joss.00550).
See Also
Other help:
tar_reprex()
,
use_targets()
,
use_targets_rmd()
Deprecated: callr
arguments.
Description
Deprecated on 2022-08-05 (targets
version 0.13.1).
Please use tar_callr_args_default()
instead.
Usage
callr_args_default(callr_function, reporter = NULL)
Arguments
callr_function |
A function from the |
reporter |
Character of length 1, choice of reporter
for |
Details
Not a user-side function. Do not invoke directly. Exported for internal purposes only.
Value
A list of arguments to callr_function
.
Examples
tar_callr_args_default(callr::r)
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- tidyselect
all_of
,any_of
,contains
,ends_with
,everything
,last_col
,matches
,num_range
,one_of
,starts_with
RStudio addin to call tar_glimpse()
.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_glimpse()
RStudio addin to call tar_load()
on the symbol at the cursor.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_load(context = NULL)
Arguments
context |
RStudio API context from
|
RStudio addin to run tar_make()
in the background.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_make_bg()
RStudio addin to call tar_outdated()
.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_outdated()
RStudio addin to print tail(tar_progress())
.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_progress()
RStudio addin to call tar_read()
on the symbol at the cursor.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_read(context = NULL)
Arguments
context |
RStudio API context from
|
RStudio addin to insert "tar_target()"
at the cursor.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_target(context = NULL)
Arguments
context |
RStudio API context from
|
RStudio addin to call tar_visnetwork()
.
Description
For internal use only. Not a user-side function.
Usage
rstudio_addin_tar_visnetwork()
Show if the pipeline is running.
Description
Return TRUE
if called in a target or _targets.R
and
the pipeline is running.
Usage
tar_active()
Value
Logical of length 1, TRUE
if called in a target or _targets.R
and the pipeline is running (FALSE
otherwise).
See Also
Other utilities:
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_active() # FALSE
tar_script({
library(targets)
library(tarchetypes)
message("Pipeline running? ", tar_active())
tar_target(x, tar_active())
})
tar_manifest() # prints "Pipeline running? FALSE"
tar_make() # prints "pipeline running? TRUE"
tar_read(x) # TRUE
})
}
Assertions
Description
These functions assert the correctness of user inputs
and generate custom error conditions as needed. Useful
for writing packages built on top of targets
.
Usage
tar_assert_chr(x, msg = NULL)
tar_assert_dbl(x, msg = NULL)
tar_assert_df(x, msg = NULL)
tar_assert_equal_lengths(x, msg = NULL)
tar_assert_envir(x, msg = NULL)
tar_assert_expr(x, msg = NULL)
tar_assert_flag(x, choices, msg = NULL)
tar_assert_file(x)
tar_assert_finite(x, msg = NULL)
tar_assert_function(x, msg = NULL)
tar_assert_function_arguments(x, args, msg = NULL)
tar_assert_ge(x, threshold, msg = NULL)
tar_assert_identical(x, y, msg = NULL)
tar_assert_in(x, choices, msg = NULL)
tar_assert_not_dirs(x, msg = NULL)
tar_assert_not_dir(x, msg = NULL)
tar_assert_not_in(x, choices, msg = NULL)
tar_assert_inherits(x, class, msg = NULL)
tar_assert_int(x, msg = NULL)
tar_assert_internet(msg = NULL)
tar_assert_lang(x, msg = NULL)
tar_assert_le(x, threshold, msg = NULL)
tar_assert_list(x, msg = NULL)
tar_assert_lgl(x, msg = NULL)
tar_assert_name(x)
tar_assert_named(x, msg = NULL)
tar_assert_names(x, msg = NULL)
tar_assert_nonempty(x, msg = NULL)
tar_assert_null(x, msg = NULL)
tar_assert_not_expr(x, msg = NULL)
tar_assert_nzchar(x, msg = NULL)
tar_assert_package(package, msg = NULL)
tar_assert_path(path, msg = NULL)
tar_assert_match(x, pattern, msg = NULL)
tar_assert_nonmissing(x, msg = NULL)
tar_assert_positive(x, msg = NULL)
tar_assert_scalar(x, msg = NULL)
tar_assert_store(store)
tar_assert_target(x, msg = NULL)
tar_assert_target_list(x)
tar_assert_true(x, msg = NULL)
tar_assert_unique(x, msg = NULL)
tar_assert_unique_targets(x)
Arguments
x |
R object, input to be validated. The kind of object depends on the specific assertion function called. |
msg |
Character of length 1, a message to be printed to the console
if |
choices |
Character vector of choices of |
args |
Character vector of expected function argument names. Order matters. |
threshold |
Numeric of length 1, lower/upper bound for
assertions like |
y |
R object, value to compare against |
class |
Character vector of expected class names. |
package |
Character of length 1, name of an R package. |
path |
Character, file path. |
pattern |
Character of length 1, a |
store |
Character of length 1, path to the data store of the pipeline. |
See Also
Other utilities to extend targets:
tar_condition
,
tar_language
,
tar_test()
Examples
tar_assert_chr("123")
try(tar_assert_chr(123))
Superseded: exponential backoff
Description
Superseded: configure exponential backoff while polling for tasks during the pipeline.
Usage
tar_backoff(min = 0.001, max = 0.1, rate = 1.5)
Arguments
min |
Positive numeric of length 1,
minimum polling interval in seconds.
Must be at least |
max |
Positive numeric of length 1,
maximum polling interval in seconds.
Must be at least |
rate |
Positive numeric of length 1, greater than or equal to 1.
Multiplicative rate parameter that allows the exponential backoff
minimum polling interval to increase from |
Details
This function is superseded and is now only relevant to other
superseded functions tar_make_clustermq()
and tar_make_future()
.
tar_make()
uses crew
in an efficient non-polling way, making
exponential backoff unnecessary.
Backoff
In high-performance computing it can be expensive to repeatedly poll the
priority queue if no targets are ready to process. The number of seconds
between polls is runif(1, min, max(max, min * rate ^ index))
,
where index
is the number of consecutive polls so far that found
no targets ready to skip or run, and min
, max
, and rate
are arguments to tar_backoff()
.
(If no target is ready, index
goes up by 1. If a target is ready,
index
resets to 0. For more information on exponential,
backoff, visit https://en.wikipedia.org/wiki/Exponential_backoff).
Raising min
or max
is kinder to the CPU etc. but may incur delays
in some instances.
See Also
Other utilities:
tar_active()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_option_set(backoff = tar_backoff(min = 0.001, max = 0.1, rate = 1.5))
})
}
Combine pipeline objects (deprecated).
Description
Functions tar_pipeline()
and tar_bind()
are deprecated.
Instead, simply end your target script file
(default: _targets.R
) file with a list of target objects.
You can nest these objects however you like.
Usage
tar_bind(...)
Arguments
... |
Pipeline objects or nested lists of pipeline objects.
You can generate a pipeline object with |
Details
Deprecated on 2021-01-03.
Examples
# In your target script file (default: _targets.R):
library(targets)
list( # You no longer need tar_pipeline() here.
tar_target(data_file, "data.csv", format = "file"),
list( # Target lists can be arbitrarily nested.
tar_target(data_object, read.csv(data_file)),
tar_target(analysis, analyze(data_object))
)
)
Integer branch indexes
Description
Get the integer indexes of individual branch names within their corresponding dynamic branching targets.
Usage
tar_branch_index(names, store = targets::tar_config_get("store"))
Arguments
names |
Character vector of branch names. |
store |
Character of length 1, path to the
|
Value
A named integer vector of branch indexes.
See Also
Other branching:
tar_branch_names()
,
tar_branches()
,
tar_pattern()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(4)),
tar_target(y, 2 * x, pattern = map(x)),
tar_target(z, y, pattern = map(y))
)
}, ask = FALSE)
tar_make()
names <- c(
tar_meta(y, children)$children[[1]][c(2, 3)],
tar_meta(z, children)$children[[1]][2]
)
names
tar_branch_index(names) # c(2, 3, 2)
})
}
Branch names
Description
Get the branch names of a dynamic branching target
using numeric indexes.
tar_branch_names()
expects an unevaluated symbol
for the name
argument, whereas tar_branch_names_raw()
expects a character string for name
.
Usage
tar_branch_names(name, index, store = targets::tar_config_get("store"))
tar_branch_names_raw(name, index, store = targets::tar_config_get("store"))
Arguments
name |
Name of the dynamic branching target.
|
index |
Integer vector of branch indexes. |
store |
Character string, directory path to the
|
Value
A character vector of branch names.
See Also
Other branching:
tar_branch_index()
,
tar_branches()
,
tar_pattern()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(4)),
tar_target(y, 2 * x, pattern = map(x)),
tar_target(z, y, pattern = map(y))
)
}, ask = FALSE)
tar_make()
tar_branch_names(z, c(2, 3))
})
}
Reconstruct the branch names and the names of their dependencies.
Description
Given a branching pattern, use available metadata to reconstruct branch names and the names of each branch's dependencies. The metadata of each target must already exist and be consistent with the metadata of the other targets involved.
Usage
tar_branches(
name,
pattern = NULL,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
name |
Symbol, name of the target. |
pattern |
Language to define branching for a target
(just like in |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
Details
The results from this function can help you retroactively figure out correspondences between upstream branches and downstream branches. However, it does not always correctly predict what the names of the branches will be after the next run of the pipeline. Dynamic branching happens while the pipeline is running, so we cannot always know what the names of the branches will be in advance (or even how many there will be).
Value
A tibble
with one row per branch and one column for each target
(including the branched-over targets and the target with the pattern.)
See Also
Other branching:
tar_branch_index()
,
tar_branch_names()
,
tar_pattern()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, head(letters, 2)),
tar_target(z, head(LETTERS, 2)),
tar_target(dynamic, c(x, y, z), pattern = cross(z, map(x, y)))
)
}, ask = FALSE)
tar_make()
tar_branches(dynamic)
tar_branches(dynamic, pattern = cross(z, map(x, y)))
})
}
Deprecated: list built targets.
Description
Deprecated in favor of tar_completed()
on 2023-12-04
(targets
version 1.3.2.9004).
Usage
tar_built(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
store |
Character of length 1, path to the
|
Value
A character vector of completed targets.
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_completed()
tar_completed(starts_with("y_")) # see also any_of()
})
}
Identify the called targets
function.
Description
Get the name of the currently running targets
interface function. Returns NULL
if not invoked inside
a target or _targets.R
(i.e. if not directly invoked
by tar_make()
, tar_visnetwork()
, etc.).
Usage
tar_call()
Value
Character of length 1, name of the currently running targets
interface function. For example, suppose you have a call to
tar_call()
inside a target or _targets.R
. Then if you run
tar_make()
, tar_call()
will return "tar_make"
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_call() # NULL
tar_script({
library(targets)
library(tarchetypes)
message("called function: ", tar_call())
tar_target(x, tar_call())
})
tar_manifest() # prints "called function: tar_manifest"
tar_make() # prints "called function: tar_make"
tar_read(x) # "tar_make"
})
}
Default callr
arguments.
Description
Default callr
arguments for the callr_arguments
argument of tar_make()
and related functions.
Usage
tar_callr_args_default(callr_function, reporter = NULL)
Arguments
callr_function |
A function from the |
reporter |
Character of length 1, choice of reporter
for |
Details
Not a user-side function. Do not invoke directly. Exported for internal purposes only.
Value
A list of arguments to callr_function
.
Examples
tar_callr_args_default(callr::r)
Invoke a targets
task from inside a callr
function
(without error handling).
Description
Not a user-side function. Do not invoke directly. Exported for internal purposes only.
Usage
tar_callr_inner_try(
targets_function,
targets_arguments,
options,
envir = NULL,
parent,
script,
store,
fun,
pid_parent
)
Arguments
targets_function |
A function from |
targets_arguments |
Named list of arguments of targets_function. |
options |
Names of global options to temporarily set
in the |
envir |
Name of the environment to run in. If |
parent |
Parent environment of the call to
|
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
fun |
Character of length 1, name of the |
pid_parent |
Integer of length 1, process ID of the calling process,
e.g. the one that called |
Value
The output of a call to a targets
function that uses
callr
for reproducibility.
Examples
# See the examples of tar_make().
Cancel a target mid-execution under a custom condition.
Description
Cancel a target while its command is running if a condition is met.
Usage
tar_cancel(condition = TRUE)
Arguments
condition |
Logical of length 1, whether to cancel the target. |
Details
Must be invoked by the target itself. tar_cancel()
cannot interrupt a target from another process.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(x, tar_cancel(1 > 0)))
tar_make() # Should cancel target x.
})
}
List canceled targets.
Description
List targets whose progress is "canceled"
.
Usage
tar_canceled(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
store |
Character of length 1, path to the
|
Value
A character vector of canceled targets.
See Also
Other progress:
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_canceled()
tar_canceled(starts_with("y_")) # see also any_of()
})
}
Local CAS download.
Description
For internal use only.
Usage
tar_cas_d(cas, key, path)
Arguments
cas |
File path to the CAS repository. |
key |
Key of the object in the CAS system. |
path |
Staging path of the file. |
Value
Called for its side effects.
Check existence in local CAS.
Description
For internal use only.
Usage
tar_cas_e(cas, key)
Arguments
cas |
File path to the CAS repository. |
key |
Key of the object in the CAS system. |
Details
The short function name helps reduce the size of the
tar_repository_cas()
format string and save space in the metadata.
Value
Character vector of keys (metadata hashes) found in the CAS system.
List keys in local CAS.
Description
For internal use only.
Usage
tar_cas_l(cas, keys)
Arguments
cas |
File path to the CAS repository. |
keys |
Character vector of keys in the metadata hashes
( |
Details
The short function name helps reduce the size of the
tar_repository_cas()
format string and save space in the metadata.
Value
Character vector of keys (metadata hashes) found in the CAS system.
Local CAS upload.
Description
For internal use only.
Usage
tar_cas_u(cas, key, path)
Arguments
cas |
File path to the CAS repository. |
key |
Key of the object in the CAS system. |
path |
Staging path of the file. |
Details
The short function name helps reduce the size of the
tar_repository_cas()
format string and save space in the metadata.
Value
Called for its side effects.
List completed targets.
Description
List targets whose progress is "completed"
.
Usage
tar_completed(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
store |
Character of length 1, path to the
|
Value
A character vector of completed targets.
See Also
Other progress:
tar_canceled()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_completed()
tar_completed(starts_with("y_")) # see also any_of()
})
}
Conditions
Description
These functions throw custom
targets
-specific error conditions.
Useful for error handling in packages built on top of targets
.
Usage
tar_message_run(...)
tar_throw_file(...)
tar_throw_run(..., class = character(0))
tar_throw_validate(...)
tar_warn_deprecate(...)
tar_warn_run(...)
tar_warn_validate(...)
tar_message_validate(...)
tar_print(...)
tar_error(message, class)
tar_warning(message, class)
tar_message(message, class)
Arguments
... |
zero or more objects which can be coerced to character (and which are pasted together with no separator) or a single condition object. |
class |
Character vector of S3 classes of the message. |
message |
Character of length 1, text of the message. |
See Also
Other utilities to extend targets:
tar_assert
,
tar_language
,
tar_test()
Examples
try(tar_throw_validate("something is not valid"))
Contain an error condition and formatted traceback.
Description
Not a user-side function.
Usage
tar_condition_traced(condition, trace)
Arguments
condition |
An error condition object thrown by |
trace |
A raw return value from |
Value
Contain an error condition and formatted traceback.
Get configuration settings.
Description
Read the custom settings for the current project in the optional YAML configuration file.
Usage
tar_config_get(
name,
config = Sys.getenv("TAR_CONFIG", "_targets.yaml"),
project = Sys.getenv("TAR_PROJECT", "main")
)
Arguments
name |
Character of length 1, name of the specific configuration setting to retrieve. |
config |
Character of length 1, file path of the YAML
configuration file with |
project |
Character of length 1, name of the current
|
Value
The value of the configuration setting from
the YAML configuration file (default: _targets.yaml
)
or the default value if the setting is not available.
The data type of the return value depends on your choice
of name
.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Configuration
For several key functions like tar_make()
, the
default values of arguments are controlled though
tar_config_get()
. tar_config_get()
retrieves data
from an optional YAML configuration file.
You can control the settings in the YAML
file programmatically with tar_config_set()
.
The default file path of this YAML file is _targets.yaml
, and you can
set another path globally using the TAR_CONFIG
environment variable. The YAML file can store configuration
settings for multiple projects, and you can globally
set the default project with the TAR_PROJECT
environment
variable.
The structure of the YAML file
follows rules similar to the config
R package, e.g.
projects can inherit settings from one another using the inherits
field.
Exceptions include:
There is no requirement to have a configuration named
"default"
.Other projects do not inherit from the default project' automatically.
Not all fields need values because
targets
already has defaults.
targets
does not actually invoke
the config
package. The implementation in targets
was written from scratch without viewing or copying any
part of the source code of config
.
See Also
Other configuration:
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(list(tar_target(x, 1 + 1)))
tar_config_get("store") # "_targets"
store_path <- tempfile()
tar_config_set(store = store_path)
tar_config_get("store") # Shows a temp file.
tar_make() # Writes to the custom data store identified in _targets.yaml.
tar_read(x) # tar_read() knows about _targets.yaml too.
file.exists("_targets") # FALSE
file.exists(store_path) # TRUE
})
}
List projects.
Description
List the names of projects defined in _targets.yaml
.
Usage
tar_config_projects(config = Sys.getenv("TAR_CONFIG", "_targets.yaml"))
Arguments
config |
Character of length 1, file path of the YAML
configuration file with |
Value
Character vector of names of projects defined in _targets.yaml
.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Configuration
For several key functions like tar_make()
, the
default values of arguments are controlled though
tar_config_get()
. tar_config_get()
retrieves data
from an optional YAML configuration file.
You can control the settings in the YAML
file programmatically with tar_config_set()
.
The default file path of this YAML file is _targets.yaml
, and you can
set another path globally using the TAR_CONFIG
environment variable. The YAML file can store configuration
settings for multiple projects, and you can globally
set the default project with the TAR_PROJECT
environment
variable.
The structure of the YAML file
follows rules similar to the config
R package, e.g.
projects can inherit settings from one another using the inherits
field.
Exceptions include:
There is no requirement to have a configuration named
"default"
.Other projects do not inherit from the default project' automatically.
Not all fields need values because
targets
already has defaults.
targets
does not actually invoke
the config
package. The implementation in targets
was written from scratch without viewing or copying any
part of the source code of config
.
See Also
Other configuration:
tar_config_get()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
yaml <- tempfile()
tar_config_set(store = "my_store_a", config = yaml, project = "project_a")
tar_config_set(store = "my_store_b", config = yaml, project = "project_b")
tar_config_projects(config = yaml)
Set configuration settings.
Description
tar_config_set()
writes special custom settings
for the current project to an optional YAML configuration file.
Usage
tar_config_set(
inherits = NULL,
as_job = NULL,
garbage_collection = NULL,
label = NULL,
label_width = NULL,
level_separation = NULL,
reporter_make = NULL,
reporter_outdated = NULL,
script = NULL,
seconds_meta_append = NULL,
seconds_meta_upload = NULL,
seconds_reporter = NULL,
seconds_reporter_outdated = NULL,
seconds_interval = NULL,
store = NULL,
shortcut = NULL,
use_crew = NULL,
workers = NULL,
config = Sys.getenv("TAR_CONFIG", "_targets.yaml"),
project = Sys.getenv("TAR_PROJECT", "main")
)
Arguments
inherits |
Character of length 1, name of the project from which
the current project should inherit configuration settings.
The current project is the |
as_job |
Logical of length 1, |
garbage_collection |
Deprecated. Use the |
label |
Argument of |
label_width |
Argument of |
level_separation |
Argument of |
reporter_make |
Character of length 1, |
reporter_outdated |
Character of length 1, |
script |
Character of length 1, path to the target script file
that defines the pipeline ( |
seconds_meta_append |
Argument of When the pipeline ends,
all the metadata and progress data is saved immediately,
regardless of |
seconds_meta_upload |
Argument of |
seconds_reporter |
Deprecated in |
seconds_reporter_outdated |
Deprecated in |
seconds_interval |
Deprecated on 2023-08-24
( |
store |
Character of length 1, path to the data store of the pipeline.
If |
shortcut |
logical of length 1, default |
use_crew |
Logical of length 1, whether to use |
workers |
Positive numeric of length 1, |
config |
Character of length 1, file path of the YAML
configuration file with |
project |
Character of length 1, name of the current
|
Value
NULL
(invisibly)
Configuration
For several key functions like tar_make()
, the
default values of arguments are controlled though
tar_config_get()
. tar_config_get()
retrieves data
from an optional YAML configuration file.
You can control the settings in the YAML
file programmatically with tar_config_set()
.
The default file path of this YAML file is _targets.yaml
, and you can
set another path globally using the TAR_CONFIG
environment variable. The YAML file can store configuration
settings for multiple projects, and you can globally
set the default project with the TAR_PROJECT
environment
variable.
The structure of the YAML file
follows rules similar to the config
R package, e.g.
projects can inherit settings from one another using the inherits
field.
Exceptions include:
There is no requirement to have a configuration named
"default"
.Other projects do not inherit from the default project' automatically.
Not all fields need values because
targets
already has defaults.
targets
does not actually invoke
the config
package. The implementation in targets
was written from scratch without viewing or copying any
part of the source code of config
.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(list(tar_target(x, 1 + 1)))
tar_config_get("store") # NULL (data store defaults to "_targets/")
store_path <- tempfile()
tar_config_set(store = store_path)
tar_config_get("store") # Shows a temp file.
tar_make() # Writes to the custom data store identified in _targets.yaml.
tar_read(x) # tar_read() knows about _targets.yaml too.
file.exists("_targets") # FALSE
file.exists(store_path) # TRUE
})
}
Unset configuration settings.
Description
Unset (i.e. delete) one or more
custom settings for the current project
from the optional YAML configuration file.
After that, tar_option_get()
will return the original
default values for those settings for the project.
Usage
tar_config_unset(
names = character(0),
config = Sys.getenv("TAR_CONFIG", "_targets.yaml"),
project = Sys.getenv("TAR_PROJECT", "main")
)
Arguments
names |
Character vector of configuration settings to delete from the current project. |
config |
Character of length 1, file path of the YAML
configuration file with |
project |
Character of length 1, name of the current
|
Value
NULL
(invisibly)
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Configuration
For several key functions like tar_make()
, the
default values of arguments are controlled though
tar_config_get()
. tar_config_get()
retrieves data
from an optional YAML configuration file.
You can control the settings in the YAML
file programmatically with tar_config_set()
.
The default file path of this YAML file is _targets.yaml
, and you can
set another path globally using the TAR_CONFIG
environment variable. The YAML file can store configuration
settings for multiple projects, and you can globally
set the default project with the TAR_PROJECT
environment
variable.
The structure of the YAML file
follows rules similar to the config
R package, e.g.
projects can inherit settings from one another using the inherits
field.
Exceptions include:
There is no requirement to have a configuration named
"default"
.Other projects do not inherit from the default project' automatically.
Not all fields need values because
targets
already has defaults.
targets
does not actually invoke
the config
package. The implementation in targets
was written from scratch without viewing or copying any
part of the source code of config
.
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(list(tar_target(x, 1 + 1)))
tar_config_get("store") # "_targets"
store_path <- tempfile()
tar_config_set(store = store_path)
tar_config_get("store") # Shows a temp file.
tar_config_unset("store")
tar_config_get("store") # _targets
})
}
Read _targets.yaml
.
Description
Read the YAML content of _targets.yaml
.
Usage
tar_config_yaml(config = Sys.getenv("TAR_CONFIG", "_targets.yaml"))
Arguments
config |
Character of length 1, file path of the YAML
configuration file with |
Value
Nested list of fields defined in _targets.yaml
.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Configuration
For several key functions like tar_make()
, the
default values of arguments are controlled though
tar_config_get()
. tar_config_get()
retrieves data
from an optional YAML configuration file.
You can control the settings in the YAML
file programmatically with tar_config_set()
.
The default file path of this YAML file is _targets.yaml
, and you can
set another path globally using the TAR_CONFIG
environment variable. The YAML file can store configuration
settings for multiple projects, and you can globally
set the default project with the TAR_PROJECT
environment
variable.
The structure of the YAML file
follows rules similar to the config
R package, e.g.
projects can inherit settings from one another using the inherits
field.
Exceptions include:
There is no requirement to have a configuration named
"default"
.Other projects do not inherit from the default project' automatically.
Not all fields need values because
targets
already has defaults.
targets
does not actually invoke
the config
package. The implementation in targets
was written from scratch without viewing or copying any
part of the source code of config
.
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
yaml <- tempfile()
tar_config_set(store = "my_store_a", config = yaml, project = "project_a")
tar_config_set(store = "my_store_b", config = yaml, project = "project_b")
str(tar_config_yaml(config = yaml))
Create a counter object.
Description
Internal function. Not for users.
Usage
tar_counter(names = NULL)
Arguments
names |
Character vector of names to set in the counter. |
Examples
tar_counter(names = "x")
Get crew worker info.
Description
For the most recent run of the pipeline with tar_make()
where a crew
controller was started, get summary-level information
of the workers.
Usage
tar_crew(store = targets::tar_config_get("store"))
Arguments
store |
Character of length 1, path to the
|
Value
A data frame one row per crew
controller
(potentially multiple rows if tar_option_get("controller")
is a controller group) and the following columns:
-
controller
: name of thecrew
controller. -
targets
: number of times the controller attempted to run a target. -
seconds
: number of seconds the workers spent running tasks.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other data:
tar_pid()
,
tar_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
if (requireNamespace("crew", quietly = TRUE)) {
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(controller = crew::crew_controller_local())
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_process()
tar_process(pid)
}
})
}
Declare the rules that cue a target.
Description
Declare the rules that mark a target as outdated.
Usage
tar_cue(
mode = c("thorough", "always", "never"),
command = TRUE,
depend = TRUE,
format = TRUE,
repository = TRUE,
iteration = TRUE,
file = TRUE,
seed = TRUE
)
Arguments
mode |
Cue mode. If |
command |
Logical, whether to rerun the target if command changed since last time. |
depend |
Logical, whether to rerun the target if the value of one of the dependencies changed. |
format |
Logical, whether to rerun the target if the user-specified
storage format changed. The storage format is user-specified through
|
repository |
Logical, whether to rerun the target if the user-specified
storage repository changed. The storage repository is user-specified
through |
iteration |
Logical, whether to rerun the target if the user-specified
iteration method changed. The iteration method is user-specified through
|
file |
Logical, whether to rerun the target if the file(s) with the return value changed or at least one is missing. |
seed |
Logical, whether to rerun the target if pseudo-random
number generator seed either changed or is |
Target invalidation rules
targets
uses internal metadata and special cues
to decide whether a target is up to date (can skip)
or is outdated/invalidated (needs to rerun). By default,
targets
moves through the following list of cues
and declares a target outdated if at least one is cue activated.
There is no metadata record of the target.
The target errored last run.
The target has a different class than it did before.
The cue mode equals
"always"
.The cue mode does not equal
"never"
.The
command
metadata field (the hash of the R command) is different from last time.The
depend
metadata field (the hash of the immediate upstream dependency targets and global objects) is different from last time.The storage format is different from last time.
The iteration mode is different from last time.
A target's file (either the one in
_targets/objects/
or a file target) does not exist or changed since last time.
The user can suppress many of the above cues using the tar_cue()
function, which creates the cue
argument of tar_target()
.
Cues objects also constitute more nuanced target invalidation rules.
The tarchetypes
package has many such examples, including
tar_age()
, tar_download()
, tar_cue_age()
, tar_cue_force()
,
and tar_cue_skip()
.
Dependency-based invalidation and user-defined functions
If the cue of a target has depend = TRUE
(default) then the target
is marked invalidated/outdated when its upstream dependencies change.
A target's dependencies include upstream targets,
user-defined functions, and other global objects populated
in the target script file (default: _targets.R
).
To determine if a given dependency changed
since the last run of the pipeline, targets
computes hashes.
The hash of a target is computed on its files in storage
(usually a file in _targets/objects/
). The hash of a
non-function global object dependency is computed directly on its
in-memory data. User-defined functions are hashed in the following way:
Deparse the function with
targets:::tar_deparse_safe()
. This function computes a string representation of the function body and arguments. This string representation is invariant to changes in comments and whitespace, which means trivial changes to formatting do not cue targets to rerun.Manually remove any literal pointers from the function string using
targets:::mask_pointers()
. Such pointers arise from inline compiled C/C++ functions.Using static code analysis (i.e.
tar_deps()
, which is based oncodetools::findGlobals()
) identify any user-defined functions and global objects that the current function depends on. Append the hashes of those dependencies to the string representation of the current function.Compute the hash of the final string representation using
targets:::hash_object()
.
Above, (3) is important because user-defined functions
have dependencies of their own, such as other user-defined
functions and other global objects. (3) ensures that a change to
a function's dependencies invalidates the function itself, which
in turn invalidates any calling functions and any targets downstream
with the depend
cue turned on.
See Also
Other targets:
tar_target()
Examples
# The following target will always run when the pipeline runs.
x <- tar_target(x, download_data(), cue = tar_cue(mode = "always"))
Print instructions for debugging a target.
Description
Not a user-side function. Do not call directly.
Usage
tar_debug_instructions()
Value
NULL
(invisibly). Messages are printed out.
Examples
tar_debug_instructions()
Deduplicate meta and progress databases (deprecated).
Description
Deprecated in targets
version 0.3.0 (2020-03-06).
Deduplication happens automatically before and after the pipeline runs.
Usage
tar_deduplicate(
meta = TRUE,
progress = TRUE,
store = targets::tar_config_get("store")
)
Arguments
meta |
Logical, whether to deduplicate the meta database file
at |
progress |
Logical, whether to deduplicate the progress database file
at |
store |
Character of length 1, path to the
|
Details
Removes duplicated entries in the meta and progress
databases in order to lighten storage. These databases are located
in the _targets/meta/meta
and _targets/meta/progress
files,
where _targets
is the a folder at the project root.
No essential data is removed, so
this is simply a form of garbage collection.
Value
Nothing.
For developers only: get the definition of the current target.
Description
For developers only: get the full definition of the
target currently running. This target definition is the same kind
of object produced by tar_target()
.
Usage
tar_definition(
default = targets::tar_target_raw("target_name", quote(identity()))
)
Arguments
default |
Environment, value to return if |
Details
Most users should not use tar_definition()
because accidental
modifications could break the pipeline.
tar_definition()
only exists in order to support third-party interface
packages, and even then the returned target definition is not modified..
Value
If called from a running target, tar_definition()
returns
the target object of the currently running target.
See the "Target objects" section for details.
Target objects
Functions like tar_target()
produce target objects,
special objects with specialized sets of S3 classes.
Target objects represent skippable steps of the analysis pipeline
as described at https://books.ropensci.org/targets/.
Please read the walkthrough at
https://books.ropensci.org/targets/walkthrough.html
to understand the role of target objects in analysis pipelines.
For developers, https://wlandau.github.io/targetopia/contributing.html#target-factories explains target factories (functions like this one which generate targets) and the design specification at https://books.ropensci.org/targets-design/ details the structure and composition of target objects.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
class(tar_definition())
tar_definition()$name
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(
tar_target(x, tar_definition()$settings$memory, memory = "transient")
)
tar_make(x)
tar_read(x)
})
}
Delete target output values.
Description
Delete the output values of targets in _targets/objects/
(or the cloud if applicable)
but keep the records in the metadata.
Usage
tar_delete(
names,
cloud = TRUE,
batch_size = 1000L,
verbose = TRUE,
store = targets::tar_config_get("store")
)
Arguments
names |
Optional, names of the targets to delete. If supplied, the
|
cloud |
Logical of length 1, whether to delete objects
from the cloud if applicable (e.g. AWS, GCP). If |
batch_size |
Positive integer between 1 and 1000, number of target 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. |
store |
Character of length 1, path to the
|
Details
If you have a small number of data-heavy targets you
need to discard to conserve storage, this function can help.
Local external files files (i.e. format = "file"
and repository = "local"
) are not deleted.
For targets with repository
not equal "local"
, tar_delete()
attempts
to delete the file and errors out if the deletion is unsuccessful.
If deletion fails, either log into the cloud platform
and manually delete the file (e.g. the AWS web console
in the case of repository = "aws"
) or call
tar_invalidate()
on that target so that targets
does not try to delete the object.
For patterns recorded in the metadata, all the branches
will be deleted. For patterns no longer in the metadata,
branches are left alone.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Cloud target data versioning
Some buckets in Amazon S3 or Google Cloud Storage are "versioned",
which means they track historical versions of each data object.
If you use targets
with cloud storage
(https://books.ropensci.org/targets/cloud-storage.html)
and versioning is turned on, then targets
will record each
version of each target in its metadata.
Functions like tar_read()
and tar_load()
load the version recorded in the local metadata,
which may not be the same as the "current" version of the
object in the bucket. Likewise, functions tar_delete()
and tar_destroy()
only remove
the version ID of each target as recorded in the local
metadata.
If you want to interact with the latest version of an object instead of the version ID recorded in the local metadata, then you will need to delete the object from the metadata.
Make sure your local copy of the metadata is current and up to date. You may need to run
tar_meta_download()
ortar_meta_sync()
first.Run
tar_unversion()
to remove the recorded version IDs of your targets in the local metadata.With the version IDs gone from the local metadata, functions like
tar_read()
andtar_destroy()
will use the latest version of each target data object.Optional: to back up the local metadata file with the version IDs deleted, use
tar_meta_upload()
.
See Also
Other clean:
tar_destroy()
,
tar_invalidate()
,
tar_prune()
,
tar_prune_list()
,
tar_unversion()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
tar_delete(starts_with("y")) # Only deletes y1 and y2.
tar_make() # y1 and y2 rerun but return the same values, so z is up to date.
})
}
Code dependencies
Description
List the dependencies of a function or expression.
tar_deps()
expects the expr
argument to be an unevaluated
expression,
whereas tar_deps_raw()
expects expr
to be an evaluated
expression object. Functions can be passed normally in either case.
Usage
tar_deps(expr)
tar_deps_raw(expr)
Arguments
expr |
An R expression or function.
|
Details
targets
detects the dependencies of commands using
static code analysis. Use tar_deps()
to run the
code analysis and see the dependencies for yourself.
Value
Character vector of the dependencies of a function or expression.
See Also
Other inspect:
tar_manifest()
,
tar_network()
,
tar_outdated()
,
tar_sitrep()
,
tar_validate()
Examples
tar_deps(x <- y + z)
tar_deps(quote(x <- y + z))
tar_deps({
x <- 1
x + a
})
tar_deps(function(a = b) map_dfr(data, ~do_row(.x)))
tar_deps_raw(function(a = b) map_dfr(data, ~do_row(.x)))
Select targets using their descriptions.
Description
Select a subset of targets in the _targets.R
file
based on their custom descriptions.
Usage
tar_described_as(
described_as = NULL,
tidyselect = TRUE,
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script")
)
Arguments
described_as |
A |
tidyselect |
If |
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 |
Details
Targets with empty descriptions are ignored.
Value
If tidyselect
is TRUE
, then tar_described_as()
returns
a call to tidyselect::all_of()
which can be supplied to the names
argument of functions like tar_manifest()
and tar_make()
.
This allows functions like tar_manifest()
and tar_make()
to focus on only the targets with the matching descriptions.
If tidyselect
is FALSE
, then tar_described_as()
returns
a simple character vector of the names of all the targets in the
pipeline with matching descriptions.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(b2, TRUE, description = "blue two"),
tar_target(b3, TRUE, description = "blue three"),
tar_target(g2, TRUE, description = "green two"),
tar_target(g3, TRUE, description = "green three"),
tar_target(g4, TRUE, description = "green three")
)
}, ask = FALSE)
tar_described_as(starts_with("green"), tidyselect = FALSE)
tar_make(names = tar_described_as(starts_with("green")))
tar_progress() # Only `g2`, `g3`, and `g4` ran.
})
}
Destroy the data store.
Description
Destroy the data store written by the pipeline.
Usage
tar_destroy(
destroy = c("all", "cloud", "local", "meta", "process", "progress", "objects",
"scratch", "workspaces", "user"),
batch_size = 1000L,
verbose = TRUE,
ask = NULL,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
destroy |
Character of length 1, what to destroy. Choices:
|
batch_size |
Positive integer between 1 and 1000, number of target 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 |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
Details
The data store is a folder created by tar_make()
(or tar_make_future()
or tar_make_clustermq()
).
The details of the data store are explained at
https://books.ropensci.org/targets/data.html#local-data-store.
The data store folder contains the output data
and metadata of the targets in the pipeline. Usually,
the data store is a folder called _targets/
(see tar_config_set()
to customize), and it may
link to data on the cloud if you used AWS or GCP
buckets. By default, tar_destroy()
deletes the entire
_targets/
folder (or wherever the data store is located),
including custom user-supplied files in _targets/user/
,
as well as any cloud data that the pipeline uploaded.
See the destroy
argument to customize this behavior
and only delete part of the data store, and see functions like
tar_invalidate()
, tar_delete()
, and tar_prune()
to remove
information pertaining to some but not all targets in the pipeline.
After calling tar_destroy()
with default arguments,
the entire data store is gone, which means all the output data from
previous runs of the pipeline is gone (except for
input/output files tracked with tar_target(..., format = "file")
).
The next run of the pipeline will start from scratch,
and it will not skip any targets.
Value
NULL
(invisibly).
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Cloud target data versioning
Some buckets in Amazon S3 or Google Cloud Storage are "versioned",
which means they track historical versions of each data object.
If you use targets
with cloud storage
(https://books.ropensci.org/targets/cloud-storage.html)
and versioning is turned on, then targets
will record each
version of each target in its metadata.
Functions like tar_read()
and tar_load()
load the version recorded in the local metadata,
which may not be the same as the "current" version of the
object in the bucket. Likewise, functions tar_delete()
and tar_destroy()
only remove
the version ID of each target as recorded in the local
metadata.
If you want to interact with the latest version of an object instead of the version ID recorded in the local metadata, then you will need to delete the object from the metadata.
Make sure your local copy of the metadata is current and up to date. You may need to run
tar_meta_download()
ortar_meta_sync()
first.Run
tar_unversion()
to remove the recorded version IDs of your targets in the local metadata.With the version IDs gone from the local metadata, functions like
tar_read()
andtar_destroy()
will use the latest version of each target data object.Optional: to back up the local metadata file with the version IDs deleted, use
tar_meta_upload()
.
See Also
Other clean:
tar_delete()
,
tar_invalidate()
,
tar_prune()
,
tar_prune_list()
,
tar_unversion()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, 1 + 1))
})
tar_make() # Creates the _targets/ data store.
tar_destroy()
print(file.exists("_targets")) # Should be FALSE.
})
}
Execute code in a temporary directory.
Description
Not a user-side function. Just for CRAN.
Usage
tar_dir(code)
Arguments
code |
User-defined code. |
Details
Runs code inside a new tempfile()
directory
in order to avoid writing to the user's file space.
Used in examples and tests in order to comply with CRAN policies.
Value
Return value of the user-defined code.
Examples
tar_dir(file.create("only_exists_in_tar_dir"))
file.exists("only_exists_in_tar_dir")
List dispatched targets.
Description
List the targets with progress status "dispatched"
.
Usage
tar_dispatched(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
function restricts its output to these targets.
You can supply symbols
or |
store |
Character of length 1, path to the
|
Details
A target is "dispatched"
if it is sent off to be run. Depending
on your high-performance computing configuration via the crew
package,
the may not actually start right away. This may happen if the target
is ready to start but all available parallel workers are busy.
Value
A character vector of dispatched targets.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_dispatched()
tar_dispatched(starts_with("y_")) # see also any_of()
})
}
Open the target script file for editing.
Description
Open the target script file for editing.
Requires the usethis
package.
Usage
tar_edit(script = targets::tar_config_get("script"))
Arguments
script |
Character of length 1, path to the
target script file. Defaults to |
Details
The target script file is an R code file
that defines the pipeline. The default path is _targets.R
,
but the default for the current project
can be configured with tar_config_set()
See Also
Other scripts:
tar_github_actions()
,
tar_helper()
,
tar_renv()
,
tar_script()
Target Markdown knitr
engine
Description
knitr
language engine that runs targets
code chunks in Target Markdown.
Usage
tar_engine_knitr(options)
Arguments
options |
A named list of |
Value
Character, output generated from knitr::engine_output()
.
Target Markdown interactive mode
Target Markdown has two modes:
Non-interactive mode. This is the default when you run
knitr::knit()
orrmarkdown::render()
. Here, the code intargets
code chunks gets written to special script files in order to set up atargets
pipeline to run later.Interactive mode: here, no scripts are written to set up a pipeline. Rather, the globals or targets in question are run in the current environment and the values are assigned to that environment.
The mode is interactive if !isTRUE(getOption("knitr.in.progress"))
,
is TRUE
. The knitr.in.progress
option is TRUE
when you run knitr::knit()
or rmarkdown::render()
and NULL
if you are running one chunk at a time interactively
in an integrated development environment, e.g. the
notebook interface in RStudio:
https://bookdown.org/yihui/rmarkdown/notebook.html.
You can choose the mode with the tar_interactive
chunk option.
(In targets
0.6.0, tar_interactive
defaults to interactive()
instead of !isTRUE(getOption("knitr.in.progress"))
.)
Target Markdown chunk options
Target Markdown introduces the following knitr
code chunk options.
Most other standard knitr
code chunk options should just work
in non-interactive mode. In interactive mode, not all
-
tar_globals
: Logical of length 1, whether to define globals or targets. IfTRUE
, the chunk code defines functions, objects, and options common to all the targets. IfFALSE
orNULL
(default), then the chunk returns formal targets for the pipeline. -
tar_interactive
: Logical of length 1, whether to run in interactive mode or non-interactive mode. See the "Target Markdown interactive mode" section of this help file for details. -
tar_name
: name to use for writing helper script files (e.g._targets_r/targets/target_script.R
) and specifying target names if thetar_simple
chunk option isTRUE
. All helper scripts and target names must have unique names, so please do not set this option globally withknitr::opts_chunk$set()
. -
tar_script
: Character of length 1, where to write the target script file in non-interactive mode. Most users can skip this option and stick with the default_targets.R
script path. Helper script files are always written next to the target script in a folder with an"_r"
suffix. Thetar_script
path must either be absolute or be relative to the project root (where you calltar_make()
or similar). If not specified, the target script path defaults totar_config_get("script")
(default:_targets.R
; helpers default:_targets_r/
). When you runtar_make()
etc. with a non-default target script, you must select the correct target script file either with thescript
argument or withtar_config_set(script = ...)
. The function willsource()
the script file from the current working directory (i.e. withchdir = FALSE
insource()
). -
tar_simple
: Logical of length 1. Set toTRUE
to define a single target with a simplified interface. In code chunks withtar_simple
equal toTRUE
, the chunk label (or thetar_name
chunk option if you set it) becomes the name, and the chunk code becomes the command. In other words, a code chunk with labeltargetname
and commandmycommand()
automatically gets converted totar_target(name = targetname, command = mycommand())
. All other arguments oftar_target()
remain at their default values (configurable withtar_option_set()
in atar_globals = TRUE
chunk).
See Also
https://books.ropensci.org/targets/literate-programming.html
Other Target Markdown:
tar_interactive()
,
tar_noninteractive()
,
tar_toggle()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
# Register the engine.
if (requireNamespace("knitr", quietly = TRUE)) {
knitr::knit_engines$set(targets = targets::tar_engine_knitr)
}
# Then, `targets` code chunks in a knitr report will run
# as described at
# <https://books.ropensci.org/targets/literate-programming.html>.
}
For developers only: get the environment of the current target.
Description
For developers only: get the environment where a
target runs its command. Designed to be called
while the target is running. The environment
inherits from tar_option_get("envir")
.
Usage
tar_envir(default = parent.frame())
Arguments
default |
Environment, value to return if |
Details
Most users should not use tar_envir()
because accidental
modifications to parent.env(tar_envir())
could break the pipeline.
tar_envir()
only exists in order to support third-party interface
packages, and even then the returned environment is not modified.
Value
If called from a running target, tar_envir()
returns
the environment where the target runs its command.
If called outside a pipeline, the return value is
whatever the user supplies to default
(which defaults to parent.frame()
).
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_envir()
tar_envir(default = new.env(parent = emptyenv()))
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(x, tar_envir(default = parent.frame())))
tar_make(x)
tar_read(x)
})
}
Show targets
environment variables.
Description
Show all the special environment variables
available for customizing targets
.
Usage
tar_envvars(unset = "")
Arguments
unset |
Character of length 1, value to return for any environment variable that is not set. |
Details
You can customize the behavior of targets
with special environment variables. The sections in this help file
describe each environment variable, and the tar_envvars()
function
lists their current values.
If you modify environment variables, please set them
in project-level .Renviron
file so you do not lose your
configuration when you restart your R session.
Modify the project-level .Renviron
file with
usethis::edit_r_environ(scope = "project")
. Restart
your R session after you are done editing.
For targets that run on parallel workers
created by tar_make_clustermq()
or tar_make_future()
,
only the environment variables listed by tar_envvars()
are specifically exported to the targets.
For all other environment variables, you will have to set
the values manually, e.g. a project-level .Renviron
file
(for workers that have access to the local file system).
Value
A data frame with one row per environment variable
and columns with the name and current value of each.
An unset environment variable will have a value of ""
by default. (Customize with the unset
argument).
TAR_ASK
The TAR_ASK
environment variable accepts values "true"
and "false"
.
If TAR_ASK
is not set, or if it is set to "true"
,
then targets
asks permission in a menu
before overwriting certain files, such as the target script file
(default: _targets.R
) in tar_script()
.
If TAR_ASK
is "false"
, then targets
overwrites the old files
with the new ones without asking. Once you are comfortable with
tar_script()
, tar_github_actions()
, and similar functions,
you can safely set TAR_ASK
to "false"
in either a project-level
or user-level .Renviron
file.
TAR_CONFIG
The TAR_CONFIG
environment variable controls the file path to the
optional YAML configuration file with project settings.
See the help file of tar_config_set()
for details.
TAR_PROJECT
The TAR_PROJECT
environment variable sets the name of project
to set and get settings when working with the YAML configuration file.
See the help file of tar_config_set()
for details.
TAR_WARN
The TAR_WARN
environment variable accepts values "true"
and "false"
.
If TAR_WARN
is not set, or if it is set to "true"
,
then targets
throws warnings in certain edge cases,
such as target/global name conflicts and dangerous use of
devtools::load_all()
. If TAR_WARN
is "false"
, then targets
does not throw warnings in these cases.
These warnings can detect potentially serious
issues with your pipeline, so please do not set TAR_WARN
unless your use case absolutely requires it.
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
tar_envvars()
List errored targets.
Description
List targets whose progress is "errored"
.
Usage
tar_errored(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
store |
Character of length 1, path to the
|
Value
A character vector of errored targets.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_errored()
tar_errored(starts_with("y_")) # see also any_of()
})
}
Check if target metadata exists.
Description
Check if the target metadata file _targets/meta/meta
exists for the current project.
Usage
tar_exist_meta(store = targets::tar_config_get("store"))
Arguments
store |
Character of length 1, path to the
|
Details
To learn more about data storage in targets
, visit
https://books.ropensci.org/targets/data.html.
Value
Logical of length 1, whether the current project's metadata exists.
See Also
Other existence:
tar_exist_objects()
,
tar_exist_process()
,
tar_exist_progress()
,
tar_exist_script()
Examples
tar_exist_meta()
Check if local output data exists for one or more targets.
Description
Check if output target data exists in either
_targets/objects/
or the cloud for one or more targets.
Usage
tar_exist_objects(
names,
cloud = TRUE,
store = targets::tar_config_get("store")
)
Arguments
names |
Character vector of target names.
Not |
cloud |
Logical of length 1, whether to include
cloud targets in the output
(e.g. |
store |
Character of length 1, path to the
|
Details
If a target has no metadata or if the repository
argument of tar_target()
was set to "local"
,
then the _targets/objects/
folder is checked. Otherwise,
if there is metadata and repsitory
is not "local"
,
then tar_exist_objects()
checks the cloud repository
selected.
Value
Logical of length length(names)
, whether
each given target has an existing file in either
_targets/objects/
or the cloud.
See Also
Other existence:
tar_exist_meta()
,
tar_exist_process()
,
tar_exist_progress()
,
tar_exist_script()
Examples
tar_exist_objects(c("target1", "target2"))
Check if process metadata exists.
Description
Check if the process metadata file _targets/meta/process
exists for the current project.
Usage
tar_exist_process(store = targets::tar_config_get("store"))
Arguments
store |
Character of length 1, path to the
|
Details
To learn more about data storage in targets
, visit
https://books.ropensci.org/targets/data.html.
Value
Logical of length 1, whether the current project's metadata exists.
See Also
Other existence:
tar_exist_meta()
,
tar_exist_objects()
,
tar_exist_progress()
,
tar_exist_script()
Examples
tar_exist_process()
Check if progress metadata exists.
Description
Check if the progress metadata file _targets/meta/progress
exists for the current project.
Usage
tar_exist_progress(store = targets::tar_config_get("store"))
Arguments
store |
Character of length 1, path to the
|
Details
To learn more about data storage in targets
, visit
https://books.ropensci.org/targets/data.html.
Value
Logical of length 1, whether the current project's metadata exists.
See Also
Other existence:
tar_exist_meta()
,
tar_exist_objects()
,
tar_exist_process()
,
tar_exist_script()
Examples
tar_exist_progress()
Check if the target script file exists.
Description
Check if the target script file exists for the
current project. The target script is _targets.R
by default,
but the path can be configured for the current project
using tar_config_set()
.
Usage
tar_exist_script(script = targets::tar_config_get("script"))
Arguments
script |
Character of length 1, path to the
target script file. Defaults to |
Value
Logical of length 1, whether the current project's metadata exists.
See Also
Other existence:
tar_exist_meta()
,
tar_exist_objects()
,
tar_exist_process()
,
tar_exist_progress()
Examples
tar_exist_script()
Define a custom target storage format.
Description
Define a custom target storage format for the
format
argument of tar_target()
or tar_option_set()
.
Usage
tar_format(
read = NULL,
write = NULL,
marshal = NULL,
unmarshal = NULL,
convert = NULL,
copy = NULL,
substitute = list(),
repository = NULL
)
Arguments
read |
A function with a single argument named |
write |
A function with two arguments: |
marshal |
A function with a single argument named |
unmarshal |
A function with a single argument named |
convert |
The |
copy |
The |
substitute |
Named list of values to be inserted into the
body of each custom function in place of symbols in the body.
For example, if
Please do not include temporary or sensitive information
such as authentication credentials.
If you do, then |
repository |
Deprecated. Use the |
Value
A character string of length 1 encoding the custom format.
You can supply this string directly to the format
argument of tar_target()
or tar_option_set()
.
Marshalling
If an object can only be used in the R session
where it was created, it is called "non-exportable".
Examples of non-exportable R objects are Keras models,
Torch objects, xgboost
matrices, xml2
documents,
rstan
model objects, sparklyr
data objects, and
database connection objects. These objects cannot be
exported to parallel workers (e.g. for tar_make_future()
)
without special treatment. To send an non-exportable
object to a parallel worker, the object must be marshalled:
converted into a form that can be exported safely
(similar to serialization but not always the same).
Then, the worker must unmarshal the object: convert it
into a form that is usable and valid in the current R session.
Arguments marshal
and unmarshal
of tar_format()
let you control how marshalling and unmarshalling happens.
Format functions
In tar_format()
, functions like read
, write
,
marshal
, and unmarshal
must be perfectly pure
and perfectly self-sufficient.
They must load or namespace all their own packages,
and they must not depend on any custom user-defined
functions or objects in the global environment of your pipeline.
targets
converts each function to and from text,
so it must not rely on any data in the closure.
This disqualifies functions produced by Vectorize()
,
for example.
The write
function must write only a single file,
and the file it writes must not be a directory.
The functions to read and write the object
should not do any conversions on the object. That is the job
of the convert
argument. The convert
argument is a function
that accepts the object returned by the command of the target
and changes it into an acceptable format (e.g. can be
saved with the read
function). Working with the convert
function is best because it ensures the in-memory copy
of an object during the running pipeline session
is the same as the copy of the object that is saved
to disk.
See Also
Other storage:
tar_load()
,
tar_load_everything()
,
tar_objects()
,
tar_read()
Examples
# The following target is equivalent to the current superseded
# tar_target(name, command(), format = "keras").
# An improved version of this would supply a `convert` argument
# to handle NULL objects, which are returned by the target if it
# errors and the error argument of tar_target() is "null".
tar_target(
name = keras_target,
command = your_function(),
format = tar_format(
read = function(path) {
keras::load_model_hdf5(path)
},
write = function(object, path) {
keras::save_model_hdf5(object = object, filepath = path)
},
marshal = function(object) {
keras::serialize_model(object)
},
unmarshal = function(object) {
keras::unserialize_model(object)
}
)
)
# And the following is equivalent to the current superseded
# tar_target(name, torch::torch_tensor(seq_len(4)), format = "torch"),
# except this version has a `convert` argument to handle
# cases when `NULL` is returned (e.g. if the target errors out
# and the `error` argument is "null" in tar_target()
# or tar_option_set())
tar_target(
name = torch_target,
command = torch::torch_tensor(),
format = tar_format(
read = function(path) {
torch::torch_load(path)
},
write = function(object, path) {
torch::torch_save(obj = object, path = path)
},
marshal = function(object) {
con <- rawConnection(raw(), open = "wr")
on.exit(close(con))
torch::torch_save(object, con)
rawConnectionValue(con)
},
unmarshal = function(object) {
con <- rawConnection(object, open = "r")
on.exit(close(con))
torch::torch_load(con)
}
)
)
Current storage format.
Description
Get the storage format of the target currently running.
Usage
tar_format_get()
Details
This function is meant to be called inside a target in a
running pipeline. If it is called outside a target in the running
pipeline, it will return the default format given by
tar_option_get("format")
.
Value
A character string, storage format of the target currently
running in the pipeline. If called outside a target in the running
pipeline, tar_format_get()
will return the default format given by
tar_option_get("format")
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_target(x, tar_format_get(), format = "qs")
Set up GitHub Actions to run a targets pipeline
Description
Writes a GitHub Actions workflow file so the pipeline
runs on every push to GitHub. Historical runs accumulate in the
targets-runs
branch, and the latest output is restored before
tar_make()
so up-to-date targets do not rerun.
Usage
tar_github_actions(
path = file.path(".github", "workflows", "targets.yaml"),
ask = NULL
)
Arguments
path |
Character of length 1, file path to write the GitHub Actions workflow file. |
ask |
Logical, whether to ask before writing if the workflow file
already exists. If |
Details
Steps to set up continuous deployment:
Ensure your pipeline stays within the resource limitations of GitHub Actions and repositories, both for storage and compute. For storage, you may wish to reduce the burden with an alternative repository (e.g.
tar_target(..., repository = "aws")
).Ensure Actions are enabled in your GitHub repository. You may have to visit the Settings tab.
Call
targets::tar_renv(extras = character(0))
to expose hidden package dependencies.Set up
renv
for your project (withrenv::init()
orrenv::snapshot()
). Details at https://rstudio.github.io/renv/articles/ci.html.Commit the
renv.lock
file to themain
(recommended) ormaster
Git branch.Run
tar_github_actions()
to create the workflow file. Commit this file tomain
(recommended) ormaster
in Git.Push your project to GitHub. Verify that a GitHub Actions workflow runs and pushes results to
targets-runs
. Subsequent runs will only recompute the outdated targets.
Value
Nothing (invisibly). This function writes a GitHub Actions workflow file as a side effect.
See Also
Other scripts:
tar_edit()
,
tar_helper()
,
tar_renv()
,
tar_script()
Examples
tar_github_actions(tempfile())
Visualize an abridged fast dependency graph.
Description
Analyze the pipeline defined in the target script file
(default: _targets.R
)
and visualize the directed acyclic graph of targets.
Unlike tar_visnetwork()
, tar_glimpse()
does not account for
metadata or progress information, which means the graph
renders faster. Also, tar_glimpse()
omits functions and other global
objects by default (but you can include them with targets_only = FALSE
).
Usage
tar_glimpse(
targets_only = TRUE,
names = NULL,
shortcut = FALSE,
allow = NULL,
exclude = ".Random.seed",
label = targets::tar_config_get("label"),
label_width = targets::tar_config_get("label_width"),
level_separation = targets::tar_config_get("level_separation"),
degree_from = 1L,
degree_to = 1L,
zoom_speed = 1,
physics = FALSE,
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
targets_only |
Logical, whether to restrict the output to just targets
( |
names |
Names of targets. The graph visualization will operate
only on these targets (and unless |
shortcut |
Logical of length 1, how to interpret the |
allow |
Optional, define the set of allowable vertices in the graph.
Unlike |
exclude |
Optional, define the set of exclude vertices from the graph.
Unlike |
label |
Character vector of one or more aesthetics to add to the
vertex labels. Currently, the only option is |
label_width |
Positive numeric of length 1, maximum width (in number of characters) of the node labels. |
level_separation |
Numeric of length 1,
|
degree_from |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
degree_to |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
zoom_speed |
Positive numeric of length 1, scaling factor on the zoom speed. Above 1 zooms faster than default, below 1 zooms lower than default. |
physics |
Logical of length 1, whether to implement interactive physics in the graph, e.g. edge elasticity. |
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
|
Value
A visNetwork
HTML widget object.
Dependency graph
The dependency graph of a pipeline is a directed acyclic graph (DAG)
where each node indicates a target or global object and each directed
edge indicates where a downstream node depends on an upstream node.
The DAG is not always a tree, but it never contains a cycle because
no target is allowed to directly or indirectly depend on itself.
The dependency graph should show a natural progression of work from
left to right. targets
uses static code analysis to create the graph,
so the order of tar_target()
calls in the _targets.R
file
does not matter. However, targets does not support self-referential
loops or other cycles. For more information on the dependency graph,
please read
https://books.ropensci.org/targets/targets.html#dependencies.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other visualize:
tar_mermaid()
,
tar_visnetwork()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set()
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_glimpse()
tar_glimpse(allow = starts_with("y")) # see also any_of()
})
}
Group a data frame to iterate over subsets of rows.
Description
Like dplyr::group_by()
, but for patterns.
tar_group()
allows you to map or cross over subsets of data frames.
Requires iteration = "group"
on the target. See the example.
Usage
tar_group(x)
Arguments
x |
Grouped data frame from |
Details
The goal of tar_group()
is to post-process the return value
of a data frame target to allow downstream targets to branch over
subsets of rows. It takes the groups defined by dplyr::group_by()
and translates that information into a special tar_group
is a column.
tar_group
is a vector of positive integers
from 1 to the number of groups. Rows with the same integer in tar_group
belong to the same group, and branches are arranged in increasing order
with respect to the integers in tar_group
.
The assignment of tar_group
integers to group levels
depends on the orderings inside the grouping variables and not the order
of rows in the dataset. dplyr::group_keys()
on the grouped data frame
shows how the grouping variables correspond to the integers in the
tar_group
column.
Value
A data frame with a special tar_group
column that
targets
will use to find subsets of your data frame.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
# The tar_group() function simply creates
# a tar_group column to partition the rows
# of a data frame.
data.frame(
x = seq_len(6),
id = rep(letters[seq_len(3)], each = 2)
) %>%
dplyr::group_by(id) %>%
tar_group()
# We use tar_group() below to branch over
# subsets of a data frame defined with dplyr::group_by().
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(dplyr)
library(targets)
library(tarchetypes)
list(
tar_target(
data,
data.frame(
x = seq_len(6),
id = rep(letters[seq_len(3)], each = 2)
) %>%
group_by(id) %>%
tar_group(),
iteration = "group"
),
tar_target(
sums,
sum(data$x),
pattern = map(data),
iteration = "vector"
)
)
})
tar_make()
tar_read(sums) # Should be c(3, 7, 11).
})
}
Write a helper R script.
Description
Write a helper R script for a targets
pipeline.
Could be supporting functions or the target script file
(default: _targets.R
) itself.
tar_helper()
expects an unevaluated expression for the code
argument, whereas tar_helper_raw()
expects an evaluated
expression object.
Usage
tar_helper(path = NULL, code = NULL, tidy_eval = TRUE, envir = parent.frame())
tar_helper_raw(path = NULL, code = NULL)
Arguments
path |
Character of length 1, path to write (or overwrite) |
code |
Code to write to |
tidy_eval |
Logical, whether to use tidy evaluation on |
envir |
Environment for tidy evaluation. |
Details
tar_helper()
is a specialized version of tar_script()
with flexible paths and tidy evaluation.
Value
NULL
(invisibly)
See Also
Other scripts:
tar_edit()
,
tar_github_actions()
,
tar_renv()
,
tar_script()
Examples
# Without tidy evaluation:
path <- tempfile()
tar_helper(path, code = x <- 1)
tar_helper_raw(path, code = quote(x <- 1)) # equivalent
writeLines(readLines(path))
# With tidy evaluation:
y <- 123
tar_helper(path, x <- !!y)
writeLines(readLines(path))
Run if Target Markdown interactive mode is on.
Description
In Target Markdown, run the enclosed code only if interactive mode is activated. Otherwise, do not run the code.
Usage
tar_interactive(code)
Arguments
code |
R code to run if Target Markdown interactive mode is turned on. |
Details
Visit <books.ropensci.org/targets/literate-programming.html> to learn about Target Markdown and interactive mode.
Value
If Target Markdown interactive mode is turned on,
the function returns the result of running the code.
Otherwise, the function invisibly returns NULL
.
See Also
Other Target Markdown:
tar_engine_knitr()
,
tar_noninteractive()
,
tar_toggle()
Examples
tar_interactive(message("In interactive mode."))
Delete one or more metadata records (e.g. to rerun a target).
Description
Delete the metadata of records in _targets/meta/meta
but keep the return values of targets in _targets/objects/
.
Usage
tar_invalidate(names, store = targets::tar_config_get("store"))
Arguments
names |
Names of the targets to remove from the metadata list.
The object supplied to |
store |
Character of length 1, path to the
|
Details
This function forces one or more targets to rerun
on the next tar_make()
, regardless of the cues and regardless
of how those targets are stored. After tar_invalidate()
,
you will still be able to locate the data files with tar_path_target()
and manually salvage them in an emergency.
However, tar_load()
and tar_read()
will not be able to
read the data into R, and subsequent calls to tar_make()
will attempt to rerun those targets.
For patterns recorded in the metadata, all the branches
will be invalidated. For patterns no longer in the metadata,
branches are left alone.
Value
NULL
(invisibly).
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other clean:
tar_delete()
,
tar_destroy()
,
tar_prune()
,
tar_prune_list()
,
tar_unversion()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
tar_invalidate(starts_with("y")) # Only invalidates y1 and y2.
tar_make() # y1 and y2 rerun but return same values, so z is up to date.
})
}
Language
Description
These functions help with metaprogramming in
packages built on top of targets
.
Usage
tar_deparse_language(expr)
tar_deparse_safe(expr, collapse = "\n", backtick = TRUE)
tar_tidy_eval(expr, envir, tidy_eval)
tar_tidyselect_eval(names_quosure, choices)
Arguments
expr |
A language object to modify or deparse. |
collapse |
Character of length 1, delimiter in deparsing. |
backtick |
logical indicating whether symbolic names should be enclosed in backticks if they do not follow the standard syntax. |
envir |
An environment to find objects for tidy evaluation. |
tidy_eval |
Logical of length 1, whether to apply tidy evaluation. |
names_quosure |
An |
choices |
A character vector of choices for character elements returned by tidy evaluation. |
Details
-
tar_deparse_language()
is a wrapper aroundtar_deparse_safe()
which leaves character vectors andNULL
objects alone, which helps with subsequent user input validation. -
tar_deparse_safe()
is a wrapper aroundbase::deparse()
with a custom set of fast default settings and guardrails to ensure the output always has length 1. -
tar_tidy_eval()
applies tidy evaluation to a language object and returns another language object. -
tar_tidyselect_eval()
appliestidyselect
selection with some special guardrails aroundNULL
inputs.
See Also
Other utilities to extend targets:
tar_assert
,
tar_condition
,
tar_test()
Examples
tar_deparse_language(quote(run_model()))
Load the values of targets.
Description
Load the return values of targets into the current environment
(or the environment of your choosing). For a typical target, the return
value lives in a file in _targets/objects/
. For file targets (i.e.
format = "file"
) the paths loaded in place of the values.
tar_load_everything()
is shorthand for tar_load(everything())
to load all targets.
tar_load()
uses non-standard evaluation in the names
argument
(example: tar_load(names = everything())
), whereas tar_load_raw()
uses standard evaluation for names
(example: tar_load_raw(names = quote(everything()))
).
Usage
tar_load(
names,
branches = NULL,
meta = targets::tar_meta(targets_only = TRUE, store = store),
strict = TRUE,
silent = FALSE,
envir = parent.frame(),
store = targets::tar_config_get("store")
)
tar_load_raw(
names,
branches = NULL,
meta = tar_meta(store = store),
strict = TRUE,
silent = FALSE,
envir = parent.frame(),
store = targets::tar_config_get("store")
)
Arguments
names |
Names of the targets to load.
The object supplied to |
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. |
Value
Nothing.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Cloud target data versioning
Some buckets in Amazon S3 or Google Cloud Storage are "versioned",
which means they track historical versions of each data object.
If you use targets
with cloud storage
(https://books.ropensci.org/targets/cloud-storage.html)
and versioning is turned on, then targets
will record each
version of each target in its metadata.
Functions like tar_read()
and tar_load()
load the version recorded in the local metadata,
which may not be the same as the "current" version of the
object in the bucket. Likewise, functions tar_delete()
and tar_destroy()
only remove
the version ID of each target as recorded in the local
metadata.
If you want to interact with the latest version of an object instead of the version ID recorded in the local metadata, then you will need to delete the object from the metadata.
Make sure your local copy of the metadata is current and up to date. You may need to run
tar_meta_download()
ortar_meta_sync()
first.Run
tar_unversion()
to remove the recorded version IDs of your targets in the local metadata.With the version IDs gone from the local metadata, functions like
tar_read()
andtar_destroy()
will use the latest version of each target data object.Optional: to back up the local metadata file with the version IDs deleted, use
tar_meta_upload()
.
See Also
Other storage:
tar_format()
,
tar_load_everything()
,
tar_objects()
,
tar_read()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
ls() # Does not have "y1", "y2", or "z".
tar_load(starts_with("y"))
ls() # Has "y1" and "y2" but not "z".
tar_load_raw(quote(any_of("z")))
ls() # Has "y1", "y2", and "z".
})
}
Load the values of all available targets.
Description
Shorthand for tar_load(everything())
to load all
targets with entries in the metadata.
Usage
tar_load_everything(
branches = NULL,
meta = tar_meta(targets_only = TRUE, store = store),
strict = TRUE,
silent = FALSE,
envir = parent.frame(),
store = targets::tar_config_get("store")
)
Arguments
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. |
Value
Nothing.
See Also
Other storage:
tar_format()
,
tar_load()
,
tar_objects()
,
tar_read()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
ls() # Does not have "y1", "y2", or "z".
tar_load_everything()
ls() # Has "y1", "y2", and "z".
})
}
Load globals for debugging, testing, and prototyping
Description
Load user-defined packages, functions, global objects, and
settings defined in the target script file (default: _targets.R
).
This function is for debugging, testing, and prototyping only.
It is not recommended for use inside a serious pipeline
or to report the results of a serious pipeline.
Usage
tar_load_globals(
envir = parent.frame(),
script = targets::tar_config_get("script")
)
Arguments
envir |
Environment to source the target script (default: |
script |
Character of length 1, path to the target script file
that defines the pipeline ( |
Details
This function first sources the target script file
(default: _targets.R
)
to loads all user-defined functions, global objects, and settings
into the current R process. Then, it loads all the packages defined
in tar_option_get("packages")
(default: (.packages())
)
using library()
with lib.loc
defined in tar_option_get("library")
(default: NULL
).
Value
NULL
(invisibly).
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other debug:
tar_traceback()
,
tar_workspace()
,
tar_workspace_download()
,
tar_workspaces()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(packages = "callr")
analyze_data <- function(data) {
summary(data)
}
list(
tar_target(x, 1 + 1),
tar_target(y, 1 + 1)
)
}, ask = FALSE)
tar_load_globals()
print(analyze_data)
print("callr" %in% (.packages()))
})
}
Run a pipeline of targets.
Description
Run the pipeline you defined in the targets
script file (default: _targets.R
). tar_make()
runs the correct targets in the correct order and stores the return
values in _targets/objects/
. Use tar_read()
to read a target
back into R, and see
https://docs.ropensci.org/targets/reference/index.html#clean
to manage output files.
Usage
tar_make(
names = NULL,
shortcut = targets::tar_config_get("shortcut"),
reporter = targets::tar_config_get("reporter_make"),
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")
)
Arguments
names |
Names of the targets to run or check. Set to |
shortcut |
Logical of length 1, how to interpret the |
reporter |
Character of length 1, name of the reporter to user.
Controls how messages are printed as targets run in the pipeline.
Defaults to The default of
|
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 |
|
Value
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.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other pipeline:
tar_make_clustermq()
,
tar_make_future()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make(starts_with("y")) # Only processes y1 and y2.
# Distributed computing with crew:
if (requireNamespace("crew", quietly = TRUE)) {
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(controller = crew::controller_local())
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
}
})
}
Superseded. Run a pipeline with persistent clustermq
workers.
Description
Superseded. Use tar_make()
with crew
:
https://books.ropensci.org/targets/crew.html.
Usage
tar_make_clustermq(
names = NULL,
shortcut = targets::tar_config_get("shortcut"),
reporter = targets::tar_config_get("reporter_make"),
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"),
workers = targets::tar_config_get("workers"),
log_worker = FALSE,
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
)
Arguments
names |
Names of the targets to run or check. Set to |
shortcut |
Logical of length 1, how to interpret the |
reporter |
Character of length 1, name of the reporter to user.
Controls how messages are printed as targets run in the pipeline.
Defaults to The default of
|
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 |
workers |
Positive integer, number of persistent |
log_worker |
Logical, whether to write a log file for each worker.
Same as the |
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 |
Details
tar_make_clustermq()
is like tar_make()
except that targets
run in parallel on persistent workers. A persistent worker is an
R process that runs for a long time and runs multiple
targets during its lifecycle. Persistent
workers launch as soon as the pipeline reaches an outdated
target with deployment = "worker"
, and they keep running
until the pipeline starts to wind down.
To configure tar_make_clustermq()
, you must configure
the clustermq
package. To do this, set global options
clustermq.scheduler
and clustermq.template
inside the target script file (default: _targets.R
).
To read more about configuring clustermq
for your scheduler, visit
https://mschubert.github.io/clustermq/articles/userguide.html#configuration # nolint
or https://books.ropensci.org/targets/hpc.html.
clustermq
is not a strict dependency of targets
,
so you must install clustermq
yourself.
Value
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.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other pipeline:
tar_make()
,
tar_make_future()
Examples
if (!identical(tolower(Sys.info()[["sysname"]]), "windows")) {
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
options(clustermq.scheduler = "multiprocess") # Does not work on Windows.
tar_option_set()
list(tar_target(x, 1 + 1))
}, ask = FALSE)
tar_make_clustermq()
})
}
}
Superseded. Run a pipeline of targets in parallel with transient
future
workers.
Description
Superseded. Use tar_make()
with crew
:
https://books.ropensci.org/targets/crew.html.
Usage
tar_make_future(
names = NULL,
shortcut = targets::tar_config_get("shortcut"),
reporter = targets::tar_config_get("reporter_make"),
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"),
workers = targets::tar_config_get("workers"),
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
)
Arguments
names |
Names of the targets to run or check. Set to |
shortcut |
Logical of length 1, how to interpret the |
reporter |
Character of length 1, name of the reporter to user.
Controls how messages are printed as targets run in the pipeline.
Defaults to The default of
|
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 |
workers |
Positive integer, maximum number of transient
|
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 |
Details
This function is like tar_make()
except that targets
run in parallel with transient future
workers. It requires
that you declare your future::plan()
inside the
target script file (default: _targets.R
).
future
is not a strict dependency of targets
,
so you must install future
yourself.
To configure tar_make_future()
with a computing cluster,
see the future.batchtools
package documentation.
Value
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.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other pipeline:
tar_make()
,
tar_make_clustermq()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
future::plan(future::multisession, workers = 2)
list(
tar_target(x, 1 + 1),
tar_target(y, 1 + 1)
)
}, ask = FALSE)
tar_make_future()
})
}
Interactive mode pipeline
Description
Not a user-side function. Do not invoke directly. Only exported to on a technicality.
Usage
tar_make_interactive(code)
Arguments
code |
Character vector of lines of a |
Value
NULL
(invisibly).
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_make_interactive("library(targets); tar_target(x, 123)")
message(x)
}
Produce a data frame of information about your targets.
Description
Along with tar_visnetwork()
and tar_glimpse()
,
tar_manifest()
helps check that you constructed your pipeline correctly.
Usage
tar_manifest(
names = NULL,
fields = tidyselect::any_of(c("name", "command", "pattern", "description")),
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")
)
Arguments
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 |
Value
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).
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other inspect:
tar_deps()
,
tar_network()
,
tar_outdated()
,
tar_sitrep()
,
tar_validate()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set()
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2),
tar_target(m, z, pattern = map(z), description = "branching over z"),
tar_target(c, z, pattern = cross(z))
)
}, ask = FALSE)
tar_manifest()
tar_manifest(fields = any_of(c("name", "command")))
tar_manifest(fields = any_of("command"))
tar_manifest(fields = starts_with("cue"))
})
}
mermaid.js
dependency graph.
Description
Visualize the dependency graph with a static mermaid.js
graph.
Usage
tar_mermaid(
targets_only = FALSE,
names = NULL,
shortcut = FALSE,
allow = NULL,
exclude = ".Random.seed",
outdated = TRUE,
label = targets::tar_config_get("label"),
label_width = targets::tar_config_get("label_width"),
legend = TRUE,
color = TRUE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
targets_only |
Logical, whether to restrict the output to just targets
( |
names |
Names of targets. The graph visualization will operate
only on these targets (and unless |
shortcut |
Logical of length 1, how to interpret the |
allow |
Optional, define the set of allowable vertices in the graph.
Unlike |
exclude |
Optional, define the set of exclude vertices from the graph.
Unlike |
outdated |
Logical, whether to show colors to distinguish outdated
targets from up-to-date targets. (Global functions and objects
still show these colors.) Looking for outdated targets
takes a lot of time for large pipelines with lots of branches,
and setting |
label |
Character vector of one or more aesthetics to add to the
vertex labels. Can contain |
label_width |
Positive numeric of length 1, maximum width (in number of characters) of the node labels. |
legend |
Logical of length 1, whether to display the legend. |
color |
Logical of length 1, whether to color the graph vertices by status. |
reporter |
Character of length 1, name of the reporter to user. Controls how messages are printed as targets are checked. The default of * `"balanced"`: a reporter that balances efficiency with informative detail. Uses a `cli` progress bar instead of printing messages for individual dynamic branches. To the right of the progress bar is a text string like "22.6s, 4510+, 124-" (22.6 seconds elapsed, 4510 targets detected as outdated so far, 124 targets detected as up to date so far). For best results with the balanced reporter, you may need to adjust your `cli` settings. See global options `cli.num_colors` and `cli.dynamic` at <https://cli.r-lib.org/reference/cli-config.html>. On that page is also the `CLI_TICK_TIME` environment variable which controls the time delay between progress bar updates. If the delay is too low, then overhead from printing to the console may slow down the pipeline. * `"terse"`: like `"balanced"`, except without a progress bar. * `"silent"`: print nothing. |
seconds_reporter |
Deprecated on 2025-03-31
( |
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
|
Details
mermaid.js
is a JavaScript library for constructing
static visualizations of graphs.
Value
A character vector of lines of code of the mermaid.js
graph.
You can visualize the graph by copying the text
into a public online mermaid.js
editor or a mermaid
GitHub code chunk
(https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/
).
Alternatively, you can render it inline in an R Markdown or Quarto
document using a results = "asis"
code chunk like so:
```{r, results = "asis", echo = FALSE} cat(c("```{mermaid}", targets::tar_mermaid(), "```"), sep = "\n") ```
Dependency graph
The dependency graph of a pipeline is a directed acyclic graph (DAG)
where each node indicates a target or global object and each directed
edge indicates where a downstream node depends on an upstream node.
The DAG is not always a tree, but it never contains a cycle because
no target is allowed to directly or indirectly depend on itself.
The dependency graph should show a natural progression of work from
left to right. targets
uses static code analysis to create the graph,
so the order of tar_target()
calls in the _targets.R
file
does not matter. However, targets does not support self-referential
loops or other cycles. For more information on the dependency graph,
please read
https://books.ropensci.org/targets/targets.html#dependencies.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other visualize:
tar_glimpse()
,
tar_visnetwork()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set()
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2, description = "sum of two other sums")
)
})
# Copy the text into a mermaid.js online editor
# or a mermaid GitHub code chunk:
tar_mermaid()
})
}
Read a project's metadata.
Description
Read the metadata of all recorded targets and global objects.
Usage
tar_meta(
names = NULL,
fields = NULL,
targets_only = FALSE,
complete_only = FALSE,
store = targets::tar_config_get("store")
)
Arguments
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
|
Details
A metadata row only updates when the target completes.
tar_progress()
shows information on targets that are running.
That is why the number of branches may disagree between tar_meta()
and tar_progress()
for actively running pipelines.
Value
A data frame with one row per target/object and the selected fields.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Cloud metadata
Metadata files help targets
read data objects and decide if the pipeline is up to date.
Usually, these metadata files live in files in the local
_targets/meta/
folder in your project, e.g. _targets/meta/meta
.
But in addition, if you set repository
to anything other than
"local"
in tar_option_set()
in _targets.R
, then tar_make()
continuously uploads the metadata files to the bucket you specify
in resources
. tar_meta_delete()
will delete those files from the
cloud, and so will tar_destroy()
if destroy
is
set to either "all"
or "cloud"
.
Other functions in targets
, such as tar_meta()
,
tar_visnetwork()
, tar_outdated()
, and tar_invalidate()
,
use the local metadata only and ignore the copies on the cloud.
So if you are working on a different computer than the
one running the pipeline, you will need to download the cloud metadata
to your current machine using tar_meta_download()
. Other functions
tar_meta_upload()
, tar_meta_sync()
, and tar_meta_delete()
also manage metadata across the cloud and the local file system.
Remarks:
The
repository_meta
option intar_option_set()
is actually what controls where the metadata lives in the cloud, but it defaults torepository
.Like
tar_make()
,tar_make_future()
andtar_make_clustermq()
also continuously upload metadata files to the cloud bucket specified inresources
.-
tar_meta_download()
and related functions need to run_targets.R
to detecttar_option_set()
optionsrepository_meta
andresources
, so please be aware of side effects that may happen running your custom_targets.R
file.
See Also
Other metadata:
tar_meta_delete()
,
tar_meta_download()
,
tar_meta_sync()
,
tar_meta_upload()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_meta()
tar_meta(starts_with("y_")) # see also any_of()
})
}
Delete metadata.
Description
Delete the project metadata files from the local file system, the cloud, or both.
Usage
tar_meta_delete(
meta = TRUE,
progress = TRUE,
process = TRUE,
crew = TRUE,
verbose = TRUE,
delete = "all",
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
meta |
Logical of length 1, whether to process the main metadata file
at |
progress |
Logical of length 1, whether to process the progress file at
|
process |
Logical of length 1, whether to process the process file at
|
crew |
Logical of length 1, whether to process the |
verbose |
Logical of length 1, whether to print informative console messages. |
delete |
Character of length 1, which location to delete the files.
Choose |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
See Also
Other metadata:
tar_meta()
,
tar_meta_download()
,
tar_meta_sync()
,
tar_meta_upload()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(
resources = tar_resources(
aws = tar_resources_aws(
bucket = "YOUR_BUCKET_NAME",
prefix = "YOUR_PROJECT_NAME"
)
),
repository = "aws"
)
list(
tar_target(x, data.frame(x = seq_len(2), y = seq_len(2)))
)
})
tar_make()
tar_meta_delete()
})
}
download local metadata to the cloud.
Description
download local metadata files to the cloud location
(repository, bucket, and prefix) you set in
tar_option_set()
in _targets.R
.
Usage
tar_meta_download(
meta = TRUE,
progress = TRUE,
process = TRUE,
crew = TRUE,
verbose = TRUE,
strict = FALSE,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
meta |
Logical of length 1, whether to process the main metadata file
at |
progress |
Logical of length 1, whether to process the progress file at
|
process |
Logical of length 1, whether to process the process file at
|
crew |
Logical of length 1, whether to process the |
verbose |
Logical of length 1, whether to print informative console messages. |
strict |
Logical of length 1. |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
See Also
Other metadata:
tar_meta()
,
tar_meta_delete()
,
tar_meta_sync()
,
tar_meta_upload()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(
resources = tar_resources(
aws = tar_resources_aws(
bucket = "YOUR_BUCKET_NAME",
prefix = "YOUR_PROJECT_NAME"
)
),
repository = "aws"
)
list(
tar_target(x, data.frame(x = seq_len(2), y = seq_len(2)))
)
})
tar_make()
tar_meta_download()
})
}
Synchronize cloud metadata.
Description
Synchronize metadata in a cloud bucket with metadata in the local data store.
Usage
tar_meta_sync(
meta = TRUE,
progress = TRUE,
process = TRUE,
crew = TRUE,
verbose = TRUE,
prefer_local = TRUE,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
meta |
Logical of length 1, whether to process the main metadata file
at |
progress |
Logical of length 1, whether to process the progress file at
|
process |
Logical of length 1, whether to process the process file at
|
crew |
Logical of length 1, whether to process the |
verbose |
Logical of length 1, whether to print informative console messages. |
prefer_local |
Logical of length 1 to control which copy of each
metadata file takes precedence if the local hash and cloud hash
are different but the time stamps are the same. Set to |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
Details
tar_meta_sync()
synchronizes the local and cloud copies
of all the metadata files of the pipeline so that both have the
most recent copy. For each metadata file,
if the local file does not exist or is older than the cloud file,
then the cloud file is downloaded to the local file path.
Conversely, if the cloud file is older or does not exist, then the local
file is uploaded to the cloud. If the time stamps of these files are
equal, use the prefer_local
argument to determine
which copy takes precedence.
See Also
Other metadata:
tar_meta()
,
tar_meta_delete()
,
tar_meta_download()
,
tar_meta_upload()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(
resources = tar_resources(
aws = tar_resources_aws(
bucket = "YOUR_BUCKET_NAME",
prefix = "YOUR_PROJECT_NAME"
)
),
repository = "aws"
)
list(
tar_target(x, data.frame(x = seq_len(2), y = seq_len(2)))
)
}, ask = FALSE)
tar_make()
tar_meta_sync()
})
}
Upload local metadata to the cloud.
Description
Upload local metadata files to the cloud location
(repository, bucket, and prefix) you set in
tar_option_set()
in _targets.R
.
Usage
tar_meta_upload(
meta = TRUE,
progress = TRUE,
process = TRUE,
crew = TRUE,
verbose = TRUE,
strict = FALSE,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
meta |
Logical of length 1, whether to process the main metadata file
at |
progress |
Logical of length 1, whether to process the progress file at
|
process |
Logical of length 1, whether to process the process file at
|
crew |
Logical of length 1, whether to process the |
verbose |
Logical of length 1, whether to print informative console messages. |
strict |
Logical of length 1. |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
See Also
Other metadata:
tar_meta()
,
tar_meta_delete()
,
tar_meta_download()
,
tar_meta_sync()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(
resources = tar_resources(
aws = tar_resources_aws(
bucket = "YOUR_BUCKET_NAME",
prefix = "YOUR_PROJECT_NAME"
)
),
repository = "aws"
)
list(
tar_target(x, data.frame(x = seq_len(2), y = seq_len(2)))
)
}, ask = FALSE)
tar_make()
tar_meta_upload()
})
}
Get the name of the target currently running.
Description
Get the name of the target currently running.
Usage
tar_name(default = "target")
Arguments
default |
Character, value to return if |
Value
Character of length 1. If called inside a pipeline,
tar_name()
returns name of the target currently running.
Otherwise, the return value is default
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_name()
tar_name(default = "custom_target_name")
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(x, tar_name()), ask = FALSE)
tar_make()
tar_read(x)
})
}
Return the vertices and edges of a pipeline dependency graph.
Description
Analyze the pipeline defined in the target script file
(default: _targets.R
)
and return the vertices and edges of the directed acyclic graph
of dependency relationships.
Usage
tar_network(
targets_only = FALSE,
names = NULL,
shortcut = FALSE,
allow = NULL,
exclude = NULL,
outdated = TRUE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
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")
)
Arguments
targets_only |
Logical, whether to restrict the output to just targets
( |
names |
Names of targets. The graph visualization will operate
only on these targets (and unless |
shortcut |
Logical of length 1, how to interpret the |
allow |
Optional, define the set of allowable vertices in the graph.
Unlike |
exclude |
Optional, define the set of exclude vertices from the graph.
Unlike |
outdated |
Logical, whether to show colors to distinguish outdated
targets from up-to-date targets. (Global functions and objects
still show these colors.) Looking for outdated targets
takes a lot of time for large pipelines with lots of branches,
and setting |
reporter |
Character of length 1, name of the reporter to user. Controls how messages are printed as targets are checked. The default of * `"balanced"`: a reporter that balances efficiency with informative detail. Uses a `cli` progress bar instead of printing messages for individual dynamic branches. To the right of the progress bar is a text string like "22.6s, 4510+, 124-" (22.6 seconds elapsed, 4510 targets detected as outdated so far, 124 targets detected as up to date so far). For best results with the balanced reporter, you may need to adjust your `cli` settings. See global options `cli.num_colors` and `cli.dynamic` at <https://cli.r-lib.org/reference/cli-config.html>. On that page is also the `CLI_TICK_TIME` environment variable which controls the time delay between progress bar updates. If the delay is too low, then overhead from printing to the console may slow down the pipeline. * `"terse"`: like `"balanced"`, except without a progress bar. * `"silent"`: print nothing. |
seconds_reporter |
Deprecated on 2025-03-31
( |
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
|
Value
A list with two data frames: vertices
and edges
. The
vertices data frame has one row per target and columns with the
the type of the target or object (stem, branch, map, cross, function,
or object), each target's description, and each target's status
(up to date, outdated, dispatched, completed, canceled, or errored),
as well as metadata if available (seconds of runtime, bytes of
storage, and number of dynamic branches).
The edges data frame has one row for every edge and columns to
and
from
to mark the starting and terminating vertices.
Dependency graph
The dependency graph of a pipeline is a directed acyclic graph (DAG)
where each node indicates a target or global object and each directed
edge indicates where a downstream node depends on an upstream node.
The DAG is not always a tree, but it never contains a cycle because
no target is allowed to directly or indirectly depend on itself.
The dependency graph should show a natural progression of work from
left to right. targets
uses static code analysis to create the graph,
so the order of tar_target()
calls in the _targets.R
file
does not matter. However, targets does not support self-referential
loops or other cycles. For more information on the dependency graph,
please read
https://books.ropensci.org/targets/targets.html#dependencies.
See Also
Other inspect:
tar_deps()
,
tar_manifest()
,
tar_outdated()
,
tar_sitrep()
,
tar_validate()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set()
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1, description = "y2 info"),
tar_target(z, y1 + y2, description = "z info")
)
}, ask = FALSE)
tar_network(targets_only = TRUE)
})
}
List new targets
Description
List all the targets whose last successful run occurred after a certain point in time.
Usage
tar_newer(
time,
names = NULL,
inclusive = FALSE,
store = targets::tar_config_get("store")
)
Arguments
time |
A |
names |
Names of eligible targets. Targets excluded from |
inclusive |
Logical of length 1, whether to include targets
completed at exactly the |
store |
Character of length 1, path to the
|
Details
Only applies to targets with recorded time stamps:
just non-branching targets and individual dynamic branches.
As of targets
version 0.6.0, these time
stamps are available for these targets regardless of
storage format. Earlier versions of targets
do not record
time stamps for remote storage such as format = "url"
or repository = "aws"
in tar_target()
.
Value
A character vector of names of old targets with recorded timestamp metadata.
See Also
Other time:
tar_older()
,
tar_timestamp()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, seq_len(2)))
}, ask = FALSE)
tar_make()
# targets newer than 1 week ago
tar_newer(Sys.time() - as.difftime(1, units = "weeks"))
# targets newer than 1 week from now
tar_newer(Sys.time() + as.difftime(1, units = "weeks"))
# Everything is still up to date.
tar_make()
# Invalidate all targets targets newer than 1 week ago
# so they run on the next tar_make().
invalidate_these <- tar_newer(Sys.time() - as.difftime(1, units = "weeks"))
tar_invalidate(any_of(invalidate_these))
tar_make()
})
}
Run if Target Markdown interactive mode is not on.
Description
In Target Markdown, run the enclosed code only if interactive mode is not activated. Otherwise, do not run the code.
Usage
tar_noninteractive(code)
Arguments
code |
R code to run if Target Markdown interactive mode is not turned on. |
Details
Visit <books.ropensci.org/targets/literate-programming.html> to learn about Target Markdown and interactive mode.
Value
If Target Markdown interactive mode is not turned on,
the function returns the result of running the code.
Otherwise, the function invisibly returns NULL
.
See Also
Other Target Markdown:
tar_engine_knitr()
,
tar_interactive()
,
tar_toggle()
Examples
tar_noninteractive(message("Not in interactive mode."))
List saved targets
Description
List targets currently saved to _targets/objects/
or the cloud. Does not include local files
with tar_target(..., format = "file", repository = "local")
.
Usage
tar_objects(
names = NULL,
cloud = TRUE,
store = targets::tar_config_get("store")
)
Arguments
names |
Names of targets to select.
The object supplied to |
cloud |
Logical of length 1, whether to include
cloud targets in the output
(e.g. |
store |
Character of length 1, path to the
|
Value
Character vector of targets saved to _targets/objects/
.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other storage:
tar_format()
,
tar_load()
,
tar_load_everything()
,
tar_read()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, "value"))
}, ask = FALSE)
tar_make()
tar_objects()
tar_objects(starts_with("x")) # see also any_of()
})
}
List old targets
Description
List all the targets whose last successful run occurred
before a certain point in time. Combine with tar_invalidate()
,
you can use tar_older()
to automatically rerun targets at
regular intervals. See the examples for a demonstration.
Usage
tar_older(
time,
names = NULL,
inclusive = FALSE,
store = targets::tar_config_get("store")
)
Arguments
time |
A |
names |
Names of eligible targets. Targets excluded from |
inclusive |
Logical of length 1, whether to include targets
completed at exactly the |
store |
Character of length 1, path to the
|
Details
Only applies to targets with recorded time stamps:
just non-branching targets and individual dynamic branches.
As of targets
version 0.6.0, these time
stamps are available for these targets regardless of
storage format. Earlier versions of targets
do not record
time stamps for remote storage such as format = "url"
or repository = "aws"
in tar_target()
.
Value
A character vector of names of old targets with recorded timestamp metadata.
See Also
Other time:
tar_newer()
,
tar_timestamp()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, seq_len(2)))
}, ask = FALSE)
tar_make()
# targets older than 1 week ago
tar_older(Sys.time() - as.difftime(1, units = "weeks"))
# targets older than 1 week from now
tar_older(Sys.time() + as.difftime(1, units = "weeks"))
# Everything is still up to date.
tar_make()
# Invalidate all targets targets older than 1 week from now
# so they run on the next tar_make().
invalidate_these <- tar_older(Sys.time() + as.difftime(1, units = "weeks"))
tar_invalidate(any_of(invalidate_these))
tar_make()
})
}
Export options.
Description
Internal function. Not for users.
Usage
tar_option_export()
Value
A list of options from tar_option_set().
Get a target option.
Description
Get a target option. These options include default arguments to
tar_target()
such as packages, storage format,
iteration type, and cue.
Needs to be called before any calls to tar_target()
in order to take effect.
Usage
tar_option_get(name = NULL, option = NULL)
Arguments
name |
Character of length 1, name of an option to get.
Must be one of the argument names of |
option |
Deprecated, use the |
Details
This function goes well with tar_target_raw()
when it comes
to defining external interfaces on top of the targets
package to create
pipelines.
Value
Value of a target option.
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_reset()
,
tar_option_set()
,
tar_option_with()
Examples
tar_option_get("format") # default format before we set anything
tar_target(x, 1)$settings$format
tar_option_set(format = "fst_tbl") # new default format
tar_option_get("format")
tar_target(x, 1)$settings$format
tar_option_reset() # reset the format
tar_target(x, 1)$settings$format
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(cue = tar_cue(mode = "always")) # All targets always run.
list(tar_target(x, 1), tar_target(y, 2))
})
tar_make()
tar_make()
})
}
Reset all target options.
Description
Reset all target options you previously chose with
tar_option_set()
. These options are mostly configurable default
arguments to tar_target()
and tar_target_raw()
.
Usage
tar_option_reset()
Value
NULL
(invisibly).
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_set()
,
tar_option_with()
Examples
tar_option_get("format") # default format before we set anything
tar_target(x, 1)$settings$format
tar_option_set(format = "fst_tbl") # new default format
tar_option_get("format")
tar_target(x, 1)$settings$format
tar_option_reset() # reset all options
tar_target(x, 1)$settings$format
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(cue = tar_cue(mode = "always"))
tar_option_reset() # Undo option above.
list(tar_target(x, 1), tar_target(y, 2))
})
tar_make()
tar_make()
})
}
Set target options.
Description
Set target options, including default arguments to
tar_target()
such as packages, storage format,
iteration type, and cue. Only the non-null arguments are actually
set as options. See currently set options with tar_option_get()
.
To use tar_option_set()
effectively, put it in your workflow's
target script file (default: _targets.R
)
before calls to tar_target()
or tar_target_raw()
.
Usage
tar_option_set(
tidy_eval = NULL,
packages = NULL,
imports = NULL,
library = NULL,
envir = NULL,
format = NULL,
repository = NULL,
repository_meta = NULL,
iteration = NULL,
error = NULL,
memory = NULL,
garbage_collection = NULL,
deployment = NULL,
priority = NULL,
backoff = NULL,
resources = NULL,
storage = NULL,
retrieval = NULL,
cue = NULL,
description = NULL,
debug = NULL,
workspaces = NULL,
workspace_on_error = NULL,
seed = NULL,
controller = NULL,
trust_timestamps = NULL,
trust_object_timestamps = NULL
)
Arguments
tidy_eval |
Logical, whether to enable tidy evaluation
when interpreting |
packages |
Character vector of packages to load right before
the target runs or the output data is reloaded for
downstream targets. Use |
imports |
Character vector of package names.
For every package listed, There are several important limitations:
1. Namespaced calls, e.g. |
library |
Character vector of library paths to try
when loading |
envir |
Environment containing functions and global objects
common to all targets in the pipeline.
The If If Package environments should not be assigned to |
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 |
repository_meta |
Character of length 1 with the same values as
|
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 |
A non-negative integer.
If |
deployment |
Character of length 1. If |
priority |
Deprecated on 2025-04-08 ( |
backoff |
An object from |
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 |
debug |
Character vector of names of targets to run in debug mode.
To use effectively, you must set |
workspaces |
Character vector of target names.
Could be non-branching targets, whole dynamic branching targets,
or individual branch names. |
workspace_on_error |
Logical of length 1, whether to save
a workspace file for each target that throws an error.
Workspace files help with debugging.
See |
seed |
Integer of length 1, seed for generating
target-specific pseudo-random number generator seeds.
These target-specific seeds are deterministic and depend on
Either the user or third-party packages built on top of The |
controller |
A controller or controller group object
produced by the |
trust_timestamps |
Logical of length 1, whether to use file system modification timestamps to check whether the target output data files in are up to date. This is an advanced setting and usually does not need to be set by the user except on old or difficult platforms. If If However, timestamp precision varies from a few
nanoseconds at best to 2 entire seconds at worst, and timestamps
with poor precision should not be fully trusted if there is any
possibility that you will manually change the file within 2 seconds
after the pipeline finishes.
If the data store is on a file system with low-precision timestamps,
then you may
consider setting To check if your
file system has low-precision timestamps, you can run
|
trust_object_timestamps |
Deprecated. Use |
Value
NULL
(invisibly).
Storage formats
targets
has several built-in storage formats to control how return
values are saved and loaded from disk:
-
"rds"
: Default, usessaveRDS()
andreadRDS()
. Should work for most objects, but slow. -
"auto"
: either"file"
or"qs"
, depending on the return value of the target. If the return value is a character vector of existing files (and/or directories), then the format becomes"file"
beforetar_make()
saves the target. Otherwise, the format becomes"qs"
.NOTE:
format = "auto"
slows down pipelines with 10000+ targets because it creates deep copies of 20000+ internal data objects. Pipelines of this size should use a more explicit format instead of"auto"
. -
"qs"
: Usesqs2::qs_save()
andqs2::qs_read()
. Should work for most objects, much faster than"rds"
. Optionally configure settings throughtar_resources()
andtar_resources_qs()
.Prior to
targets
version 1.8.0.9014,format = "qs"
used theqs
package.qs
has since been superseded in favor ofqs2
, and so later versions oftargets
useqs2
to save new data. To read existing data,targets
first attemptsqs2::qs_read()
, and then if that fails, it falls back onqs::qread()
. -
"feather"
: Usesarrow::write_feather()
andarrow::read_feather()
(version 2.0). Much faster than"rds"
, but the value must be a data frame. Optionally setcompression
andcompression_level
inarrow::write_feather()
throughtar_resources()
andtar_resources_feather()
. Requires thearrow
package (not installed by default). -
"parquet"
: Usesarrow::write_parquet()
andarrow::read_parquet()
(version 2.0). Much faster than"rds"
, but the value must be a data frame. Optionally setcompression
andcompression_level
inarrow::write_parquet()
throughtar_resources()
andtar_resources_parquet()
. Requires thearrow
package (not installed by default). -
"fst"
: Usesfst::write_fst()
andfst::read_fst()
. Much faster than"rds"
, but the value must be a data frame. Optionally set the compression level forfst::write_fst()
throughtar_resources()
andtar_resources_fst()
. Requires thefst
package (not installed by default). -
"fst_dt"
: Same as"fst"
, but the value is adata.table
. Deep copies are made as appropriate in order to protect against the global effects of in-place modification. Optionally set the compression level the same way as for"fst"
. -
"fst_tbl"
: Same as"fst"
, but the value is atibble
. Optionally set the compression level the same way as for"fst"
. -
"keras"
: superseded bytar_format()
and incompatible witherror = "null"
(intar_target()
ortar_option_set()
). Useskeras::save_model_hdf5()
andkeras::load_model_hdf5()
. The value must be a Keras model. Requires thekeras
package (not installed by default). -
"torch"
: superseded bytar_format()
and incompatible witherror = "null"
(intar_target()
ortar_option_set()
). Usestorch::torch_save()
andtorch::torch_load()
. The value must be an object from thetorch
package such as a tensor or neural network module. Requires thetorch
package (not installed by default). -
"file"
: A file target. To use this format, the target needs to manually identify or save some data and return a character vector of paths to the data (must be a single file path ifrepository
is not"local"
). (These paths must be existing files and nonempty directories.) Then,targets
automatically checks those files and cues the appropriate run/skip decisions if those files are out of date. Those paths must point to files or directories, and they must not contain characters|
or*
. All the files and directories you return must actually exist, or elsetargets
will throw an error. (And ifstorage
is"worker"
,targets
will first stall out trying to wait for the file to arrive over a network file system.) If the target does not create any files, the return value should becharacter(0)
.If
repository
is not"local"
andformat
is"file"
, then the character vector returned by the target must be of length 1 and point to a single file. (Directories and vectors of multiple file paths are not supported for file targets on the cloud.) That output file is uploaded to the cloud and tracked for changes where it exists in the cloud. As oftargets
version >= 1.11.0, the physical file is retained locally after the target runs. (Previous versions oftargets
deleted the file locally.) -
"url"
: An input URL. For this storage format,repository
is implicitly"local"
, URL format is likeformat = "file"
except the return value of the target is a URL that already exists and serves as input data for downstream targets. Optionally supply a customcurl
handle throughtar_resources()
andtar_resources_url()
. innew_handle()
,nobody = TRUE
is important because it ensurestargets
just downloads the metadata instead of the entire data file when it checks time stamps and hashes. The data file at the URL needs to have an ETag or a Last-Modified time stamp, or else the target will throw an error because it cannot track the data. Also, use extreme caution when trying to useformat = "url"
to track uploads. You must be absolutely certain the ETag and Last-Modified time stamp are fully updated and available by the time the target's command finishes running.targets
makes no attempt to wait for the web server. A custom format can be supplied with
tar_format()
. For this choice, it is the user's responsibility to provide methods for (un)serialization and (un)marshaling the return value of the target.The formats starting with
"aws_"
are deprecated as of 2022-03-13 (targets
version > 0.10.0). For cloud storage integration, use therepository
argument instead.
Formats "rds"
, "file"
, and "url"
are general-purpose formats
that belong in the targets
package itself.
Going forward, any additional formats should be implemented with
tar_format()
in third-party packages like tarchetypes
and geotargets
(for example: tarchetypes::tar_format_nanoparquet()
).
Formats "qs"
, "fst"
, etc. are legacy formats from before the
existence of tar_format()
, and they will continue to remain in
targets
without deprecation.
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_with()
Examples
tar_option_get("format") # default format before we set anything
tar_target(x, 1)$settings$format
tar_option_set(format = "fst_tbl") # new default format
tar_option_get("format")
tar_target(x, 1)$settings$format
tar_option_reset() # reset the format
tar_target(x, 1)$settings$format
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(cue = tar_cue(mode = "always")) # All targets always run.
list(tar_target(x, 1), tar_target(y, 2))
})
tar_make()
tar_make()
})
}
Locally set target options.
Description
Locally set target options for the duration of an expression, without permanently modifying the global state.
Usage
tar_option_with(expression, ..., envir_with = parent.frame())
Arguments
expression |
An R expression to run with the local option. |
... |
Named arguments to |
envir_with |
Environment to evaluate |
Value
NULL
(invisibly).
See Also
Other configuration:
tar_config_get()
,
tar_config_projects()
,
tar_config_set()
,
tar_config_unset()
,
tar_config_yaml()
,
tar_envvars()
,
tar_option_get()
,
tar_option_reset()
,
tar_option_set()
Examples
tar_option_with(
tar_target(data, get_data()),
packages = "dplyr",
cue = tar_cue(mode = "never")
)
Check which targets are outdated.
Description
Checks for outdated targets in the pipeline,
targets that will be rerun automatically if you call
tar_make()
or similar. See tar_cue()
for the rules
that decide whether a target needs to rerun.
Usage
tar_outdated(
names = NULL,
shortcut = targets::tar_config_get("shortcut"),
branches = FALSE,
targets_only = TRUE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
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")
)
Arguments
names |
Names of the targets. |
shortcut |
Logical of length 1, how to interpret the |
branches |
Logical of length 1, whether to include branch names. Including branches could get cumbersome for large pipelines. Individual branch names are still omitted when branch-specific information is not reliable: for example, when a pattern branches over an outdated target. |
targets_only |
Logical of length 1, whether to just restrict to targets
or to include functions and other global objects from the environment
created by running the target script file (default: |
reporter |
Character of length 1, name of the reporter to user. Controls how messages are printed as targets are checked. The default of * `"balanced"`: a reporter that balances efficiency with informative detail. Uses a `cli` progress bar instead of printing messages for individual dynamic branches. To the right of the progress bar is a text string like "22.6s, 4510+, 124-" (22.6 seconds elapsed, 4510 targets detected as outdated so far, 124 targets detected as up to date so far). For best results with the balanced reporter, you may need to adjust your `cli` settings. See global options `cli.num_colors` and `cli.dynamic` at <https://cli.r-lib.org/reference/cli-config.html>. On that page is also the `CLI_TICK_TIME` environment variable which controls the time delay between progress bar updates. If the delay is too low, then overhead from printing to the console may slow down the pipeline. * `"terse"`: like `"balanced"`, except without a progress bar. * `"silent"`: print nothing. |
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
|
Details
Requires that you define a pipeline
with a target script file (default: _targets.R
).
(See tar_script()
for details.)
Value
Names of the outdated targets.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other inspect:
tar_deps()
,
tar_manifest()
,
tar_network()
,
tar_sitrep()
,
tar_validate()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(list(tar_target(x, 1 + 1)))
tar_outdated()
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_outdated()
})
}
Deprecated: identify the file path where a target will be stored.
Description
Deprecated: identify the file path where a target will be stored after the target finishes running in the pipeline.
Usage
tar_path(
name = NULL,
default = NA_character_,
create_dir = FALSE,
store = targets::tar_config_get("store")
)
Arguments
name |
Symbol, name of a target.
If |
default |
Character, value to return if |
create_dir |
Logical of length 1,
whether to create |
store |
Character of length 1, path to the data store if |
Details
tar_path()
was deprecated on 2022-10-11 (version 0.13.5.9000).
Use tar_path_target()
instead.
Value
Character, file path of the return value of the target.
If not called from inside a running target,
tar_path(name = your_target)
just returns
_targets/objects/your_target
, the file path where your_target
will be saved unless format
is equal to "file"
or any of the
supported cloud-based storage formats.
For non-cloud storage formats, if you call tar_path()
with no arguments while target x
is running, the name
argument defaults to the name of the running target,
so tar_path()
returns _targets/objects/x
.
For cloud-backed formats, tar_path()
returns the
path to the staging file in _targets/scratch/
.
That way, even if you select a cloud repository
(e.g. tar_target(..., repository = "aws", storage = "none")
)
then you can still manually write to tar_path(create_dir = TRUE)
and the targets
package will automatically hash it and
upload it to the AWS S3 bucket. This does not apply to
format = "file"
, where you would never need storage = "none"
anyway.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_path_target()
tar_path_target(your_target)
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(returns_path, tar_path_target()), ask = FALSE)
tar_make()
tar_read(returns_path)
})
}
Current target script path
Description
Identify the file path to the target script of the pipeline currently running.
Usage
tar_path_script()
Value
Character, file path to the target script
of the pipeline currently running.
If called outside of the pipeline currently running,
tar_path_script()
returns tar_config_get("script")
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_path_script()
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
script <- tempfile()
tar_script(tar_target(x, tar_path_script()), script = script, ask = FALSE)
tar_make(script = script)
tar_read(x)
})
}
Directory path to the support scripts of the current target script
Description
Identify the directory path to the support scripts of the current target script of the pipeline currently running.
Usage
tar_path_script_support()
Details
A target script (default: _targets.R
) comes with
support scripts if it is written by Target Markdown.
These support scripts usually live in a folder called _targets_r/
,
but the path may vary from case to case. The
tar_path_scipt_support()
returns the path to
the folder with the support scripts.
Value
Character, directory path to the target script
of the pipeline currently running.
If called outside of the pipeline currently running,
tar_path_script()
returns tar_config_get("script")
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_path_script_support()
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
script <- tempfile()
tar_script(
tar_target(x, tar_path_script_support()),
script = script,
ask = FALSE
)
tar_make(script = script)
tar_read(x)
})
}
Current data store path
Description
Identify the file path to the data store of the pipeline currently running.
Usage
tar_path_store()
Value
Character, file path to the data store
of the pipeline currently running.
If called outside of the pipeline currently running,
tar_path_store()
returns tar_config_get("store")
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_target()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_path_store()
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(x, tar_path_store()), ask = FALSE)
store <- tempfile()
tar_make(store = store)
tar_read(x, store = store)
})
}
Identify the file path where a target will be stored.
Description
Identify the file path where a target will be stored after the target finishes running in the pipeline.
Usage
tar_path_target(
name = NULL,
default = NA_character_,
create_dir = FALSE,
store = targets::tar_config_get("store")
)
Arguments
name |
Symbol, name of a target.
If |
default |
Character, value to return if |
create_dir |
Logical of length 1,
whether to create |
store |
Character of length 1,
path to the data store if |
Value
Character, file path of the return value of the target.
If not called from inside a running target,
tar_path_target(name = your_target)
just returns
_targets/objects/your_target
, the file path where your_target
will be saved unless format
is equal to "file"
or any of the
supported cloud-based storage formats.
For non-cloud storage formats, if you call tar_path_target()
with no arguments while target x
is running, the name
argument defaults to the name of the running target,
so tar_path_target()
returns _targets/objects/x
.
For cloud-backed formats, tar_path_target()
returns the
path to the staging file in _targets/scratch/
.
That way, even if you select a cloud repository
(e.g. tar_target(..., repository = "aws", storage = "none")
)
then you can still manually write to
tar_path_target(create_dir = TRUE)
and the targets
package will automatically hash it and
upload it to the AWS S3 bucket. This does not apply to
format = "file"
, where you would never need storage = "none"
anyway.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_source()
,
tar_store()
,
tar_unblock_process()
Examples
tar_path_target()
tar_path_target(your_target)
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(returns_path, tar_path_target()), ask = FALSE)
tar_make()
tar_read(returns_path)
})
}
Emulate dynamic branching.
Description
Emulate the dynamic branching process outside a pipeline.
tar_pattern()
can help you understand the overall branching structure
that comes from the pattern
argument of tar_target()
.
Usage
tar_pattern(pattern, ..., seed = 0L)
Arguments
pattern |
Function call with the pattern specification. |
... |
Named integers, each of length 1. Each name is the name of a dependency target, and each integer is the length of the target (number of branches or slices). Names must be unique. |
seed |
Integer of length 1, random number generator seed to
emulate the pattern reproducibly. (The |
Details
Dynamic branching is a way to programmatically
create multiple new targets based on the values of other targets,
all while the pipeline is running. Use the pattern
argument of
tar_target()
to get started. pattern
accepts a function call
composed of target names and any of the following patterns:
-
map()
: iterate over one or more targets in sequence. -
cross()
: iterate over combinations of slices of targets. -
slice()
: select one or more slices by index, e.g.slice(x, index = c(3, 4))
selects the third and fourth slice or branch ofx
. -
head()
: restrict branching to the first few elements. -
tail()
: restrict branching to the last few elements. -
sample()
: restrict branching to a random subset of elements.
Value
A tibble
showing the kinds of dynamic branches that
tar_target()
would create in a real pipeline with the given pattern
.
Each row is a dynamic branch, each column is a dependency target,
and each element is the name of an upstream bud or branch that the
downstream branch depends on. Buds are pieces of non-branching targets
("stems") and branches are pieces of patterns. The returned bud and branch
names are not the actual ones you will see when you run the pipeline,
but they do communicate the branching structure of the pattern.
See Also
Other branching:
tar_branch_index()
,
tar_branch_names()
,
tar_branches()
Examples
# To use dynamic map for real in a pipeline,
# call map() in a target's pattern.
# The following code goes at the bottom of
# your target script file (default: `_targets.R`).
list(
tar_target(x, seq_len(2)),
tar_target(y, head(letters, 2)),
tar_target(dynamic, c(x, y), pattern = map(x, y)) # 2 branches
)
# Likewise for more complicated patterns.
list(
tar_target(x, seq_len(2)),
tar_target(y, head(letters, 2)),
tar_target(z, head(LETTERS, 2)),
tar_target(dynamic, c(x, y, z), pattern = cross(z, map(x, y))) #4 branches
)
# But you can emulate dynamic branching without running a pipeline
# in order to understand the patterns you are creating. Simply supply
# the pattern and the length of each dependency target.
# The returned data frame represents the branching structure of the pattern:
# One row per new branch, one column per dependency target, and
# one element per bud/branch in each dependency target.
tar_pattern(
cross(x, map(y, z)),
x = 2,
y = 3,
z = 3
)
tar_pattern(
head(cross(x, map(y, z)), n = 2),
x = 2,
y = 3,
z = 3
)
Get main process ID.
Description
Get the process ID (PID) of the most recent main R process to orchestrate the targets of the current project.
Usage
tar_pid(store = targets::tar_config_get("store"))
Arguments
store |
Character of length 1, path to the
|
Details
The main process is the R process invoked
by tar_make()
or similar. If callr_function
is not NULL
,
this is an external process, and the pid
in the return value
will not agree with Sys.getpid()
in your current interactive session.
The process may or may not be alive. You may want to
check it with ps::ps_is_running(ps::ps_handle(targets::tar_pid()))
before running another call to tar_make()
for the same project.
Value
Integer with the process ID (PID) of the most recent main R process to orchestrate the targets of the current project.
See Also
Other data:
tar_crew()
,
tar_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
Sys.getpid()
tar_pid() # Different from the current PID.
})
}
Declare a pipeline (deprecated).
Description
Functions tar_pipeline()
and tar_bind()
are deprecated.
Instead, simply end your target script file (default: _targets.R
)
with a list of target objects.
You can nest these objects however you like.
Usage
tar_pipeline(...)
Arguments
... |
Targets or lists of targets defined with |
Details
Deprecated on 2021-01-03.
Value
A pipeline object.
Examples
# In _targets.R:
library(targets)
list( # You no longer need tar_pipeline() here.
tar_target(data_file, "data.csv", format = "file"),
list( # Target lists can be arbitrarily nested.
tar_target(data_object, read.csv(data_file)),
tar_target(analysis, analyze(data_object))
)
)
Repeatedly poll progress in the R console.
Description
Print the information in tar_progress_summary()
at regular intervals.
Usage
tar_poll(
interval = 1,
timeout = Inf,
fields = c("skipped", "dispatched", "completed", "errored", "canceled", "since"),
store = targets::tar_config_get("store")
)
Arguments
interval |
Number of seconds to wait between iterations of polling progress. |
timeout |
How many seconds to run before exiting. |
fields |
Optional character vector of names of progress data
columns to read. Set to |
store |
Character of length 1, path to the
|
Value
NULL
(invisibly). Called for its side effects.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
list(
tar_target(x, seq_len(100)),
tar_target(y, Sys.sleep(0.1), pattern = map(x))
)
}, ask = FALSE)
px <- tar_make(callr_function = callr::r_bg, reporter = "silent")
tar_poll()
})
}
Get main process info.
Description
Get info on the most recent main R process to orchestrate the targets of the current project.
Usage
tar_process(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the data points to return.
If supplied, |
store |
Character of length 1, path to the
|
Details
The main process is the R process invoked
by tar_make()
or similar. If callr_function
is not NULL
,
this is an external process, and the pid
in the return value
will not agree with Sys.getpid()
in your current interactive session.
The process may or may not be alive. You may want to
check the status with tar_pid() %in% ps::ps_pids()
before running another call to tar_make()
for the same project.
Value
A data frame with metadata on the most recent main R process
to orchestrate the targets of the current project.
The output includes the pid
of the main process.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other data:
tar_crew()
,
tar_pid()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_process()
tar_process(pid)
})
}
Read progress.
Description
Read a project's target progress data for the most recent
run of tar_make()
or similar. Only the most recent record is shown.
Usage
tar_progress(
names = NULL,
fields = "progress",
store = targets::tar_config_get("store")
)
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
fields |
Optional, names of progress data columns to read.
Set to |
store |
Character of length 1, path to the
|
Value
A data frame with one row per target and the following columns:
-
name
: name of the target. -
type
: type of target:"stem"
for non-branching targets,"pattern"
for dynamically branching targets, and"branch"
for dynamic branches. -
parent
: name of the target's parent. For branches, this is the name of the associated pattern. For other targets, the pattern is just itself. -
branches
: number of dynamic branches of a pattern. 0 for non-patterns. -
progress
: the most recent progress update of that target. Could be"dispatched"
,"completed"
, "skipped
","canceled"
, or"errored"
."dispatched"
means the target was sent off to be run, but in the case oftar_make()
with acrew
controller, the target might not actually start running right away if thecrew
workers are all busy.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_progress()
tar_progress(starts_with("y_")) # see also any_of()
})
}
Tabulate the progress of dynamic branches.
Description
Read a project's target progress data for the most recent run of the pipeline and display the tabulated status of dynamic branches. Only the most recent record is shown.
Usage
tar_progress_branches(
names = NULL,
fields = NULL,
store = targets::tar_config_get("store")
)
Arguments
names |
Optional, names of the targets. If supplied, |
fields |
Optional, names of progress data columns to read.
Set to |
store |
Character of length 1, path to the
|
Value
A data frame with one row per target per progress status and the following columns.
-
name
: name of the pattern. -
progress
: progress status:"dispatched"
,"completed"
,"canceled"
, or"errored"
. -
branches
: number of branches in the progress category. -
total
: total number of branches planned for the whole pattern. Values within the same pattern should all be equal.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, x, pattern = map(x)),
tar_target(z, stopifnot(y < 1.5), pattern = map(y))
)
}, ask = FALSE)
try(tar_make())
tar_progress_branches()
})
}
Summarize target progress.
Description
Summarize the progress of a run of the pipeline.
Usage
tar_progress_summary(
fields = c("skipped", "dispatched", "completed", "errored", "canceled", "since"),
store = targets::tar_config_get("store")
)
Arguments
fields |
Optional character vector of names of progress data
columns to read. Set to |
store |
Character of length 1, path to the
|
Value
A data frame with one row and the following
optional columns that can be selected with fields
.
(time
is omitted by default.)
-
dispatched
: number of targets that were sent off to run and did not (yet) finish. These targets may not actually be running, depending on the status and workload of parallel workers. -
completed
: number of targets that completed without error or cancellation. -
errored
: number of targets that threw an error. -
canceled
: number of canceled targets (seetar_cancel()
). -
since
: how long ago progress last changed (Sys.time() - time
). -
time
: the time when the progress last changed (modification timestamp of the_targets/meta/progress
file).
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, seq_len(2)),
tar_target(y, x, pattern = map(x)),
tar_target(z, stopifnot(y < 1.5), pattern = map(y), error = "continue")
)
}, ask = FALSE)
try(tar_make())
tar_progress_summary()
})
}
Remove targets that are no longer part of the pipeline.
Description
Remove target values from _targets/objects/
and the cloud
and remove target metadata from _targets/meta/meta
for targets that are no longer part of the pipeline.
Usage
tar_prune(
cloud = TRUE,
batch_size = 1000L,
verbose = TRUE,
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
cloud |
Logical of length 1, whether to delete objects
from the cloud if applicable (e.g. AWS, GCP). If |
batch_size |
Positive integer between 1 and 1000, number of target 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. |
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
|
Details
tar_prune()
is useful if you recently worked through
multiple changes to your project and are now trying to
discard irrelevant data while keeping the results that still matter.
Global objects and local files with format = "file"
outside the
data store are unaffected. Also removes _targets/scratch/
,
which is only needed while tar_make()
, tar_make_clustermq()
,
or tar_make_future()
is running. To list the targets that will be
pruned without actually removing anything, use tar_prune_list()
.
Value
NULL
except if callr_function
is callr::r_bg
, in which case
a handle to the callr
background process is returned. Either way,
the value is invisibly returned.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
Cloud target data versioning
Some buckets in Amazon S3 or Google Cloud Storage are "versioned",
which means they track historical versions of each data object.
If you use targets
with cloud storage
(https://books.ropensci.org/targets/cloud-storage.html)
and versioning is turned on, then targets
will record each
version of each target in its metadata.
Functions like tar_read()
and tar_load()
load the version recorded in the local metadata,
which may not be the same as the "current" version of the
object in the bucket. Likewise, functions tar_delete()
and tar_destroy()
only remove
the version ID of each target as recorded in the local
metadata.
If you want to interact with the latest version of an object instead of the version ID recorded in the local metadata, then you will need to delete the object from the metadata.
Make sure your local copy of the metadata is current and up to date. You may need to run
tar_meta_download()
ortar_meta_sync()
first.Run
tar_unversion()
to remove the recorded version IDs of your targets in the local metadata.With the version IDs gone from the local metadata, functions like
tar_read()
andtar_destroy()
will use the latest version of each target data object.Optional: to back up the local metadata file with the version IDs deleted, use
tar_meta_upload()
.
See Also
tar_prune_inspect
Other clean:
tar_delete()
,
tar_destroy()
,
tar_invalidate()
,
tar_prune_list()
,
tar_unversion()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
# Remove some targets from the pipeline.
tar_script(list(tar_target(y1, 1 + 1)), ask = FALSE)
# Keep only the remaining targets in the data store.
tar_prune()
})
}
List targets that tar_prune()
will remove.
Description
List the targets that tar_prune()
will remove. Does not
actually remove any targets.
Usage
tar_prune_list(
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
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
|
Details
See tar_prune()
for details.
Value
If callr_function
is callr::r_bg
, the return value is
a handle to the callr
background process is returned.
Otherwise, the return value is a character vector of target names
identifying targets that tar_prune()
will remove.
See Also
tar_prune
Other clean:
tar_delete()
,
tar_destroy()
,
tar_invalidate()
,
tar_prune()
,
tar_unversion()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2)
)
}, ask = FALSE)
tar_make()
# Remove some targets from the pipeline.
tar_script(list(tar_target(y1, 1 + 1)), ask = FALSE)
# List targets that tar_prune() will remove.
tar_prune_list()
})
}
Random TCP port
Description
Not a user-side function. Exported for infrastructure purposes only.
Not a user-side function. Exported for infrastructure purposes only.
Usage
tar_random_port(lower = 49152L, upper = 65355L)
tar_random_port(lower = 49152L, upper = 65355L)
Arguments
lower |
Integer of length 1, lowest possible port. |
upper |
Integer of length 1, highest possible port. |
Value
A random port not likely to be used by another process.
A random port not likely to be used by another process.
Examples
if (requireNamespace("parallelly", quietly = TRUE)) {
tar_random_port()
}
if (requireNamespace("parallelly", quietly = TRUE)) {
tar_random_port()
}
Read a target's value from storage.
Description
Read a target's return value from its file in
_targets/objects/
. For file targets (i.e. format = "file"
)
the paths are returned.
tar_read()
expects an
unevaluated symbol for the name
argument, whereas tar_read_raw()
expects a character string.
Usage
tar_read(
name,
branches = NULL,
meta = tar_meta(store = store),
store = targets::tar_config_get("store")
)
tar_read_raw(
name,
branches = NULL,
meta = tar_meta(store = store),
store = targets::tar_config_get("store")
)
Arguments
name |
Name of the target to read.
|
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
|
Value
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.
Cloud target data versioning
Some buckets in Amazon S3 or Google Cloud Storage are "versioned",
which means they track historical versions of each data object.
If you use targets
with cloud storage
(https://books.ropensci.org/targets/cloud-storage.html)
and versioning is turned on, then targets
will record each
version of each target in its metadata.
Functions like tar_read()
and tar_load()
load the version recorded in the local metadata,
which may not be the same as the "current" version of the
object in the bucket. Likewise, functions tar_delete()
and tar_destroy()
only remove
the version ID of each target as recorded in the local
metadata.
If you want to interact with the latest version of an object instead of the version ID recorded in the local metadata, then you will need to delete the object from the metadata.
Make sure your local copy of the metadata is current and up to date. You may need to run
tar_meta_download()
ortar_meta_sync()
first.Run
tar_unversion()
to remove the recorded version IDs of your targets in the local metadata.With the version IDs gone from the local metadata, functions like
tar_read()
andtar_destroy()
will use the latest version of each target data object.Optional: to back up the local metadata file with the version IDs deleted, use
tar_meta_upload()
.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other storage:
tar_format()
,
tar_load()
,
tar_load_everything()
,
tar_objects()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, 1 + 1))
})
tar_make()
tar_read(x)
tar_read_raw("x")
})
}
Set up package dependencies for compatibility with renv
Description
Write package dependencies to a script file
(by default, named _targets_packages.R
in the root project directory).
Each package is written to a separate line
as a standard library()
call (e.g. library(package)
) so
renv
can identify them automatically.
Usage
tar_renv(
extras = c("bslib", "crew", "gt", "markdown", "rstudioapi", "shiny", "shinybusy",
"shinyWidgets", "visNetwork"),
path = "_targets_packages.R",
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script")
)
Arguments
extras |
Character vector of additional packages to declare as project dependencies. |
path |
Character of length 1, path to the script file to
populate with |
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 |
Details
This function gets called for its side-effect, which writes
package dependencies to a script for compatibility with renv
.
The generated file should not be edited by hand and will be
overwritten each time tar_renv()
is called.
The behavior of renv
is to create and manage a project-local R
library
and keep a record of project dependencies in a file called renv.lock
.
To identify dependencies, renv
crawls through code to find packages
explicitly mentioned using library()
, require()
, or ::
.
However, targets
manages packages in a way that hides dependencies
from renv.
tar_renv()
finds package dependencies that would be
otherwise hidden to renv
because they are declared using the targets
API. Thus, calling tar_renv
this is only necessary if using
tar_option_set()
or tar_target()
to use specialized storage
formats or manage packages.
With the script written by tar_renv()
, renv
is able to crawl the
file to identify package dependencies (with renv::dependencies()
).
tar_renv()
only serves to make your targets
project compatible with
renv
, it is still the users responsibility to call renv::init()
and
renv::snapshot()
directly to initialize and manage a
project-local R
library. This allows your targets
pipeline to have
its own self-contained R
library separate from your standard R
library. See https://rstudio.github.io/renv/index.html for
more information.
Value
Nothing, invisibly.
Performance
If you use renv
, then overhead from project initialization
could slow down tar_make()
and friends.
If you experience slowness, please make sure your renv
library
is on a fast file system.
(For example, slow network drives can severely reduce performance.)
In addition, you can disable the slowest renv
initialization checks.
After confirming at
https://rstudio.github.io/renv/reference/config.html
that you can safely disable these checks,
you can write lines RENV_CONFIG_RSPM_ENABLED=false
,
RENV_CONFIG_SANDBOX_ENABLED=false
,
and RENV_CONFIG_SYNCHRONIZED_CHECK=false
in your user-level .Renviron
file. If you disable the synchronization
check, remember to call renv::status()
periodically
to check the health of your renv
project library.
See Also
https://rstudio.github.io/renv/articles/renv.html
Other scripts:
tar_edit()
,
tar_github_actions()
,
tar_helper()
,
tar_script()
Examples
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(packages = c("tibble", "qs"))
list()
}, ask = FALSE)
tar_renv()
writeLines(readLines("_targets_packages.R"))
})
tar_option_reset()
Define a custom content-addressable storage (CAS) repository (an experimental feature).
Description
Define a custom storage repository that uses content-addressable storage (CAS).
Usage
tar_repository_cas(
upload,
download,
exists = NULL,
list = NULL,
consistent = FALSE,
substitute = base::list()
)
Arguments
upload |
A function with arguments To differentiate between
See the "Repository functions" section for more details. |
download |
A function with arguments Please be careful to avoid deleting the object at See the "Repository functions" section for more details. |
exists |
A function with a single argument The See the "Repository functions" section for more details. |
list |
Either The The See the "Repository functions" section for more details. |
consistent |
Logical. Set to A data storage system is said to have strong read-after-write consistency if a new object is fully available for reading as soon as the write operation finishes. Many modern cloud services like Amazon S3 and Google Cloud Storage have strong read-after-write consistency, meaning that if you upload an object with a PUT request, then a GET request immediately afterwards will retrieve the precise version of the object you just uploaded. Some storage systems do not have strong read-after-write consistency.
One example is network file systems (NFS). On a computing cluster,
if one node creates a file on an NFS, then there is a delay before
other nodes can access the new file. |
substitute |
Named list of values to be inserted into the
body of each custom function in place of symbols in the body.
For example, if
Please do not include temporary or sensitive information
such as authentication credentials.
If you do, then |
Content-addressable storage
Normally, targets
organizes output data
based on target names. For example,
if a pipeline has a single target x
with default settings,
then tar_make()
saves the output data to the file
_targets/objects/x
. When the output of x
changes, tar_make()
overwrites _targets/objects/x
.
In other words, no matter how many changes happen to x
,
the data store always looks like this:
_targets/ meta/ meta objects/ x
By contrast, with content-addressable storage (CAS),
targets
organizes outputs based on the hashes of their contents.
The name of each output file is its hash, and the
metadata maps these hashes to target names. For example, suppose
target x
has repository = tar_repository_cas_local("my_cas")
.
When the output of x
changes, tar_make()
creates a new file
inside my_cas/
without overwriting or deleting any other files
in that folder. If you run tar_make()
three different times
with three different values of x
, then storage will look like this:
_targets/ meta/ meta my_cas/ 1fffeb09ad36e84a 68328d833e6361d3 798af464fb2f6b30
The next call to tar_read(x)
uses tar_meta(x)$data
to look up the current hash of x
. If tar_meta(x)$data
returns
"1fffeb09ad36e84a"
, then tar_read(x)
returns the data from
my_cas/1fffeb09ad36e84a
. Files my_cas/68328d833e6361d3
and
and my_cas/798af464fb2f6b30
are left over from previous values of x
.
Because CAS accumulates historical data objects,
it is ideal for data versioning and collaboration.
If you commit the _targets/meta/meta
file to version control
alongside the source code,
then you can revert to a previous state of your pipeline with all your
targets up to date, and a colleague can leverage your hard-won
results using a fork of your code and metadata.
The downside of CAS is the cost of accumulating many data objects over time. Most pipelines that use CAS should have a garbage collection system or retention policy to remove data objects when they no longer needed.
The tar_repository_cas()
function lets you create your own CAS system
for targets
. You can supply arbitrary custom methods to upload,
download, and check for the existence of data objects. Your custom
CAS system can exist locally on a shared file system or remotely
on the cloud (e.g. in an AWS S3 bucket).
See the "Repository functions" section and the documentation
of individual arguments for advice on how
to write your own methods.
The tar_repository_cas_local()
function has an example
CAS system based on a local folder on disk.
It uses tar_cas_u()
for uploads,
tar_cas_d()
for downloads, and
tar_cas_l()
for listing keys.
Repository functions
In tar_repository_cas()
, functions upload
, download
,
exists
, and keys
must be completely pure and self-sufficient.
They must load or namespace all their own packages,
and they must not depend on any custom user-defined
functions or objects in the global environment of your pipeline.
targets
converts each function to and from text,
so it must not rely on any data in the closure.
This disqualifies functions produced by Vectorize()
,
for example.
upload
and download
can assume length(path)
is 1, but they should
account for the possibility that path
could be a directory. To simply
avoid supporting directories, upload
could simply call an assertion:
targets::tar_assert_not_dir( path, msg = "This CAS upload method does not support directories." )
Otherwise, support for directories may require handling them as a
special case. For example, upload
and download
could copy
all the files in the given directory,
or they could manage the directory as a zip archive.
Some functions may need to be adapted and configured based on other
inputs. For example, you may want to define
upload = \(key, path) file.rename(path, file.path(folder, key))
but do not want to hard-code a value of folder
when you write the
underlying function. The substitute
argument handles this situation.
For example, if substitute
is list(folder = "my_folder")
,
then upload
will end up as
\(key, path) file.rename(path, file.path("my_folder", key))
.
Temporary or sensitive such as authentication credentials
should not be injected
this way into the function body. Instead, pass them as environment
variables using tar_resources_repository_cas()
.
See Also
Other content-addressable storage:
tar_repository_cas_local()
,
tar_repository_cas_local_gc()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
repository <- tar_repository_cas(
upload = function(key, path) {
if (dir.exists(path)) {
stop("This CAS repository does not support directory outputs.")
}
if (!file.exists("cas")) {
dir.create("cas", recursive = TRUE)
}
file.rename(path, file.path("cas", key))
},
download = function(key, path) {
file.copy(file.path("cas", key), path)
},
exists = function(key) {
file.exists(file.path("cas", key))
},
list = function(keys) {
keys[file.exists(file.path("cas", keys))]
},
consistent = FALSE
)
write_file <- function(object) {
writeLines(as.character(object), "file.txt")
"file.txt"
}
list(
tar_target(x, c(2L, 4L), repository = repository),
tar_target(
y,
x,
pattern = map(x),
format = "qs",
repository = repository
),
tar_target(z, write_file(y), format = "file", repository = repository)
)
})
tar_make()
tar_read(y)
tar_read(z)
list.files("cas")
tar_meta(any_of(c("x", "z")), fields = any_of("data"))
})
}
Local content-addressable storage (CAS) repository (an experimental feature).
Description
Local content-addressable storage (CAS) repository.
Usage
tar_repository_cas_local(path = NULL, consistent = FALSE)
Arguments
path |
Character string, file path to the CAS repository
where all the data object files will be stored. |
consistent |
Logical. Set to A data storage system is said to have strong read-after-write consistency if a new object is fully available for reading as soon as the write operation finishes. Many modern cloud services like Amazon S3 and Google Cloud Storage have strong read-after-write consistency, meaning that if you upload an object with a PUT request, then a GET request immediately afterwards will retrieve the precise version of the object you just uploaded. Some storage systems do not have strong read-after-write consistency.
One example is network file systems (NFS). On a computing cluster,
if one node creates a file on an NFS, then there is a delay before
other nodes can access the new file. |
Details
Pass to the repository
argument of tar_target()
or
tar_option_set()
to use a local CAS system.
Value
A character string from tar_repository_cas()
which may be
passed to the repository
argument of tar_target()
or
tar_option_set()
to use a local CAS system.
Content-addressable storage
Normally, targets
organizes output data
based on target names. For example,
if a pipeline has a single target x
with default settings,
then tar_make()
saves the output data to the file
_targets/objects/x
. When the output of x
changes, tar_make()
overwrites _targets/objects/x
.
In other words, no matter how many changes happen to x
,
the data store always looks like this:
_targets/ meta/ meta objects/ x
By contrast, with content-addressable storage (CAS),
targets
organizes outputs based on the hashes of their contents.
The name of each output file is its hash, and the
metadata maps these hashes to target names. For example, suppose
target x
has repository = tar_repository_cas_local("my_cas")
.
When the output of x
changes, tar_make()
creates a new file
inside my_cas/
without overwriting or deleting any other files
in that folder. If you run tar_make()
three different times
with three different values of x
, then storage will look like this:
_targets/ meta/ meta my_cas/ 1fffeb09ad36e84a 68328d833e6361d3 798af464fb2f6b30
The next call to tar_read(x)
uses tar_meta(x)$data
to look up the current hash of x
. If tar_meta(x)$data
returns
"1fffeb09ad36e84a"
, then tar_read(x)
returns the data from
my_cas/1fffeb09ad36e84a
. Files my_cas/68328d833e6361d3
and
and my_cas/798af464fb2f6b30
are left over from previous values of x
.
Because CAS accumulates historical data objects,
it is ideal for data versioning and collaboration.
If you commit the _targets/meta/meta
file to version control
alongside the source code,
then you can revert to a previous state of your pipeline with all your
targets up to date, and a colleague can leverage your hard-won
results using a fork of your code and metadata.
The downside of CAS is the cost of accumulating many data objects over time. Most pipelines that use CAS should have a garbage collection system or retention policy to remove data objects when they no longer needed.
The tar_repository_cas()
function lets you create your own CAS system
for targets
. You can supply arbitrary custom methods to upload,
download, and check for the existence of data objects. Your custom
CAS system can exist locally on a shared file system or remotely
on the cloud (e.g. in an AWS S3 bucket).
See the "Repository functions" section and the documentation
of individual arguments for advice on how
to write your own methods.
The tar_repository_cas_local()
function has an example
CAS system based on a local folder on disk.
It uses tar_cas_u()
for uploads,
tar_cas_d()
for downloads, and
tar_cas_l()
for listing keys.
See Also
Other content-addressable storage:
tar_repository_cas()
,
tar_repository_cas_local_gc()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
repository <- tar_repository_cas_local("cas")
write_file <- function(object) {
writeLines(as.character(object), "file.txt")
"file.txt"
}
list(
tar_target(x, c(2L, 4L), repository = repository),
tar_target(
y,
x,
pattern = map(x),
format = "qs",
repository = repository
),
tar_target(z, write_file(y), format = "file", repository = repository)
)
})
tar_make()
tar_read(y)
tar_read(z)
list.files("cas")
tar_meta(any_of(c("x", "z")), fields = any_of("data"))
})
}
Local CAS garbage collection
Description
Garbage collection for a local content-addressable storage system.
Usage
tar_repository_cas_local_gc(
path = NULL,
store = targets::tar_config_get("store")
)
Arguments
path |
Character string, file path to the CAS repository
where all the data object files will be stored. |
store |
Character of length 1, path to the
|
Details
Deletes all the files in the local CAS which are not in
tar_meta(targets_only = TRUE)$data
, including all locally saved
historical data of the pipeline. This clears disk space, but
at the expense of removing historical data and data from
other colleagues who worked on the same project.
Value
NULL
(invisibly). Called for its side effects.
Removes files from the CAS repository at path
.
Content-addressable storage
Normally, targets
organizes output data
based on target names. For example,
if a pipeline has a single target x
with default settings,
then tar_make()
saves the output data to the file
_targets/objects/x
. When the output of x
changes, tar_make()
overwrites _targets/objects/x
.
In other words, no matter how many changes happen to x
,
the data store always looks like this:
_targets/ meta/ meta objects/ x
By contrast, with content-addressable storage (CAS),
targets
organizes outputs based on the hashes of their contents.
The name of each output file is its hash, and the
metadata maps these hashes to target names. For example, suppose
target x
has repository = tar_repository_cas_local("my_cas")
.
When the output of x
changes, tar_make()
creates a new file
inside my_cas/
without overwriting or deleting any other files
in that folder. If you run tar_make()
three different times
with three different values of x
, then storage will look like this:
_targets/ meta/ meta my_cas/ 1fffeb09ad36e84a 68328d833e6361d3 798af464fb2f6b30
The next call to tar_read(x)
uses tar_meta(x)$data
to look up the current hash of x
. If tar_meta(x)$data
returns
"1fffeb09ad36e84a"
, then tar_read(x)
returns the data from
my_cas/1fffeb09ad36e84a
. Files my_cas/68328d833e6361d3
and
and my_cas/798af464fb2f6b30
are left over from previous values of x
.
Because CAS accumulates historical data objects,
it is ideal for data versioning and collaboration.
If you commit the _targets/meta/meta
file to version control
alongside the source code,
then you can revert to a previous state of your pipeline with all your
targets up to date, and a colleague can leverage your hard-won
results using a fork of your code and metadata.
The downside of CAS is the cost of accumulating many data objects over time. Most pipelines that use CAS should have a garbage collection system or retention policy to remove data objects when they no longer needed.
The tar_repository_cas()
function lets you create your own CAS system
for targets
. You can supply arbitrary custom methods to upload,
download, and check for the existence of data objects. Your custom
CAS system can exist locally on a shared file system or remotely
on the cloud (e.g. in an AWS S3 bucket).
See the "Repository functions" section and the documentation
of individual arguments for advice on how
to write your own methods.
The tar_repository_cas_local()
function has an example
CAS system based on a local folder on disk.
It uses tar_cas_u()
for uploads,
tar_cas_d()
for downloads, and
tar_cas_l()
for listing keys.
See Also
Other content-addressable storage:
tar_repository_cas()
,
tar_repository_cas_local()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(seed = NA, repository = tar_repository_cas_local())
list(tar_target(x, sample.int(n = 9e9, size = 1)))
})
for (index in seq_len(3)) tar_make(reporter = "silent")
list.files("_targets/cas")
tar_repository_cas_local_gc()
list.files("_targets/cas")
tar_meta(names = any_of("x"), fields = any_of("data"))
})
}
Reproducible example of targets
with reprex
Description
Create a reproducible example of a targets
pipeline with the reprex
package.
Usage
tar_reprex(pipeline = tar_target(example_target, 1), run = tar_make(), ...)
Arguments
pipeline |
R code for the target script file |
run |
R code to inspect and run the pipeline. |
... |
Named arguments passed to |
Details
The best way to get help with an issue is to
create a reproducible example of the problem
and post it to https://github.com/ropensci/targets/discussions
tar_reprex()
facilitates this process. It is like
reprex::reprex({targets::tar_script(...); tar_make()})
,
but more convenient.
Value
A character vector of rendered the reprex, invisibly.
See Also
Other help:
targets-package
,
use_targets()
,
use_targets_rmd()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_reprex(
pipeline = {
list(
tar_target(data, data.frame(x = sample.int(1e3))),
tar_target(summary, mean(data$x, na.rm = TRUE))
)
},
run = {
tar_visnetwork()
tar_make()
}
)
}
Target resources
Description
Create a resources
argument for tar_target()
or tar_option_set()
.
Usage
tar_resources(
aws = tar_option_get("resources")$aws,
clustermq = tar_option_get("resources")$clustermq,
crew = tar_option_get("resources")$crew,
custom_format = tar_option_get("resources")$custom_format,
feather = tar_option_get("resources")$feather,
fst = tar_option_get("resources")$fst,
future = tar_option_get("resources")$future,
gcp = tar_option_get("resources")$gcp,
network = tar_option_get("resources")$network,
parquet = tar_option_get("resources")$parquet,
qs = tar_option_get("resources")$qs,
repository_cas = tar_option_get("resources")$repository_cas,
url = tar_option_get("resources")$url
)
Arguments
aws |
Output of function |
clustermq |
Output of function |
crew |
Output of function |
custom_format |
Output of function |
feather |
Output of function |
fst |
Output of function |
future |
Output of function |
gcp |
Output of function |
network |
Output of function |
parquet |
Output of function |
qs |
Output of function |
repository_cas |
Output of function |
url |
Output of function |
Value
A list of objects of class "tar_resources"
with
non-default settings of various optional backends for data storage
and high-performance computing.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "qs",
resources = tar_resources(
qs = tar_resources_qs(preset = "fast"),
future = tar_resources_future(resources = list(n_cores = 1))
)
)
Target resources: Amazon Web Services (AWS) S3 storage
Description
Create the aws
argument of tar_resources()
to specify optional settings to AWS for
tar_target(..., repository = "aws")
.
See the format
argument of tar_target()
for details.
Usage
tar_resources_aws(
bucket = targets::tar_option_get("resources")$aws$bucket,
prefix = targets::tar_option_get("resources")$aws$prefix,
region = targets::tar_option_get("resources")$aws$region,
endpoint = targets::tar_option_get("resources")$aws$endpoint,
s3_force_path_style = targets::tar_option_get("resources")$aws$s3_force_path_style,
part_size = targets::tar_option_get("resources")$aws$part_size,
page_size = targets::tar_option_get("resources")$aws$page_size,
max_tries = targets::tar_option_get("resources")$aws$max_tries,
seconds_timeout = targets::tar_option_get("resources")$aws$seconds_timeout,
close_connection = targets::tar_option_get("resources")$aws$close_connection,
verbose = targets::tar_option_get("resources")$aws$verbose,
...
)
Arguments
bucket |
Character of length 1, name of an existing bucket to upload and download the return values of the affected targets during the pipeline. |
prefix |
Character of length 1, "directory path"
in the bucket where your target object and metadata will go.
Please supply an explicit prefix
unique to your |
region |
Character of length 1, AWS region containing the S3 bucket.
Set to |
endpoint |
Character of length 1, URL endpoint for S3 storage.
Defaults to the Amazon AWS endpoint if |
s3_force_path_style |
Logical of length 1, whether to use path-style addressing for S3 requests. |
part_size |
Positive numeric of length 1, number of bytes
for each part of a multipart upload. (Except the last part,
which is the remainder.) In a multipart upload, each part
must be at least 5 MB. The default value of the |
page_size |
Positive integer of length 1, number of items in each page for paginated HTTP requests such as listing objects. |
max_tries |
Positive integer of length 1, maximum number of attempts to access a network resource on AWS. |
seconds_timeout |
Positive numeric of length 1, number of seconds until an HTTP connection times out. |
close_connection |
Logical of length 1, whether to close HTTP connections immediately. |
verbose |
Logical of length 1, whether to print console messages when running computationally expensive operations such as listing objects in a large bucket. |
... |
Named arguments to functions in
|
Details
See the cloud storage section of https://books.ropensci.org/targets/data.html for details for instructions.
Value
Object of class "tar_resources_aws"
, to be supplied
to the aws
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_target(
name,
command(),
format = "qs",
repository = "aws",
resources = tar_resources(
aws = tar_resources_aws(
bucket = "yourbucketname",
prefix = "_targets"
),
qs = tar_resources_qs(preset = "fast"),
)
)
}
Target resources: clustermq
high-performance computing
Description
Create the clustermq
argument of tar_resources()
to specify optional high-performance computing settings
for tar_make_clustermq()
.
For details, see the documentation of the clustermq
R package
and the corresponding argument names in this help file.
Usage
tar_resources_clustermq(
template = targets::tar_option_get("resources")$clustermq$template
)
Arguments
template |
Named list, |
Details
clustermq
workers are persistent,
so there is not a one-to-one correspondence between workers and targets.
The clustermq
resources apply to the workers, not the targets.
So the correct way to assign clustermq
resources is through
tar_option_set()
, not tar_target()
. clustermq
resources
in individual tar_target()
calls will be ignored.
Value
Object of class "tar_resources_clustermq"
, to be supplied
to the clustermq
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
resources = tar_resources(
clustermq = tar_resources_clustermq(template = list(n_cores = 2))
)
)
Target resources: crew
high-performance computing
Description
Create the crew
argument of tar_resources()
to specify optional target settings.
Usage
tar_resources_crew(
controller = targets::tar_option_get("resources")$crew$controller,
scale = NULL,
seconds_timeout = targets::tar_option_get("resources")$crew$seconds_timeout
)
Arguments
controller |
Character of length 1.
If |
scale |
Deprecated in |
seconds_timeout |
Positive numeric of length 1,
optional task timeout passed to the |
Details
tar_resources_crew()
accepts
target-specific settings for integration with the
crew
R package. These settings are arguments to the push()
method of the controller or controller group
object which control things like
auto-scaling behavior and the controller to use in the case
of a controller group.
Value
Object of class "tar_resources_crew"
, to be supplied
to the crew
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
resources = tar_resources(
crew = tar_resources_crew(seconds_timeout = 5)
)
)
Target resources for custom storage formats
Description
Create the custom_format
argument of tar_resources()
to specify optional target settings for custom storage formats.
Usage
tar_resources_custom_format(
envvars = targets::tar_option_get("resources")$custom_format$envvars
)
Arguments
envvars |
Named character vector of environment variables.
These environment variables are temporarily set just before each call to
the storage methods you define in |
Details
tar_resources_custom_format()
accepts
target-specific settings to customize tar_format()
storage formats.
Value
Object of class "tar_resources_custom_format"
, to be supplied
to the custom_format
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name = target_name,
command = data.frame(x = 1),
format = tar_format(
read = function(path) {
readRDS(file = path)
},
write = function(object, path) {
version <- as.integer(Sys.getenv("SERIALIZATION", unset = "2"))
saveRDS(object = object, file = path, version = version)
}
),
resources = tar_resources(
custom_format = tar_resources_custom_format(
envvars = c(SERIALIZATION = "3")
)
)
)
Target resources: feather storage formats
Description
Create the feather argument of tar_resources()
to specify optional settings for feather data frame storage formats
powered by the arrow
R package.
See the format
argument of tar_target()
for details.
Usage
tar_resources_feather(
compression = targets::tar_option_get("resources")$feather$compression,
compression_level = targets::tar_option_get("resources")$feather$compression_level
)
Arguments
compression |
Character of length 1, |
compression_level |
Numeric of length 1, |
Value
Object of class "tar_resources_feather"
, to be supplied
to the feather argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "feather",
resources = tar_resources(
feather = tar_resources_feather(compression = "lz4")
)
)
Target resources: fst
storage formats
Description
Create the fst
argument of tar_resources()
to specify optional settings for big data frame storage formats
powered by the fst
R package.
See the format
argument of tar_target()
for details.
Usage
tar_resources_fst(compress = targets::tar_option_get("resources")$fst$compress)
Arguments
compress |
Numeric of length 1, |
Value
Object of class "tar_resources_fst"
, to be supplied
to the fst
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "fst_tbl",
resources = tar_resources(
fst = tar_resources_fst(compress = 100)
)
)
Target resources: future
high-performance computing
Description
Create the future
argument of tar_resources()
to specify optional high-performance computing settings
for tar_make_future()
.
This is how to supply the resources
argument of future::future()
for targets
.
Resources supplied through
future::plan()
and future::tweak()
are completely ignored.
For details, see the documentation of the future
R package
and the corresponding argument names in this help file.
Usage
tar_resources_future(
plan = NULL,
resources = targets::tar_option_get("resources")$future$resources
)
Arguments
plan |
A |
resources |
Named list, |
Value
Object of class "tar_resources_future"
, to be supplied
to the future
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
resources = tar_resources(
future = tar_resources_future(resources = list(n_cores = 2))
)
)
Target resources: Google Cloud Platform (GCP) Google Cloud Storage (GCS)
Description
Create the gcp
argument of tar_resources()
to specify optional settings for Google Cloud Storage for
targets with tar_target(..., repository = "gcp")
.
See the format
argument of tar_target()
for details.
Usage
tar_resources_gcp(
bucket = targets::tar_option_get("resources")$gcp$bucket,
prefix = targets::tar_option_get("resources")$gcp$prefix,
predefined_acl = targets::tar_option_get("resources")$gcp$predefined_acl,
max_tries = targets::tar_option_get("resources")$gcp$max_tries,
verbose = targets::tar_option_get("resources")$gcp$verbose
)
Arguments
bucket |
Character of length 1, name of an existing bucket to upload and download the return values of the affected targets during the pipeline. |
prefix |
Character of length 1, "directory path"
in the bucket where your target object and metadata will go.
Please supply an explicit prefix
unique to your |
predefined_acl |
Character of length 1, user access
to the object. See |
max_tries |
Positive integer of length 1, number of tries accessing a network resource on GCP. |
verbose |
Logical of length 1, whether to print
extra messages like progress bars during uploads
and downloads. Defaults to |
Details
See the cloud storage section of https://books.ropensci.org/targets/data.html for details for instructions.
Value
Object of class "tar_resources_gcp"
, to be supplied
to the gcp
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "qs",
repository = "gcp",
resources = tar_resources(
gcp = tar_resources_gcp(
bucket = "yourbucketname",
prefix = "_targets"
),
qs = tar_resources_qs(preset = "fast"),
)
)
Target resources for network file systems.
Description
In high-performance computing on network file systems,
if storage = "worker"
in tar_target()
or tar_option_set()
, then
targets
waits for hashes to synchronize before continuing the pipeline.
These resources control the retry mechanism.
Usage
tar_resources_network(
max_tries = targets::tar_option_get("resources")$network$max_tries,
seconds_interval = targets::tar_option_get("resources")$network$seconds_interval,
seconds_timeout = targets::tar_option_get("resources")$network$seconds_timeout,
verbose = targets::tar_option_get("resources")$network$verbose
)
Arguments
max_tries |
Positive integer of length 1. Max number of tries. |
seconds_interval |
Positive numeric of length 1, seconds between retries. |
seconds_timeout |
Positive numeric of length 1. Timeout length in seconds. |
verbose |
Logical of length 1, whether to print informative console messages. |
Value
Object of class "tar_resources_network"
, to be supplied
to the network argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
# Somewhere in you target script file (usually _targets.R):
tar_target(
name = your_name,
command = your_command(),
storage = "worker",
resources = tar_resources(
network = tar_resources_network(max_tries = 3)
)
)
}
Target resources: parquet storage formats
Description
Create the parquet
argument of tar_resources()
to specify optional settings for parquet data frame storage formats
powered by the arrow
R package.
See the format
argument of tar_target()
for details.
Usage
tar_resources_parquet(
compression = targets::tar_option_get("resources")$parquet$compression,
compression_level = targets::tar_option_get("resources")$parquet$compression_level
)
Arguments
compression |
Character of length 1, |
compression_level |
Numeric of length 1, |
Value
Object of class "tar_resources_parquet"
, to be supplied
to the parquet argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_qs()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "parquet",
resources = tar_resources(
parquet = tar_resources_parquet(compression = "lz4")
)
)
Target resources: qs storage formats
Description
Create the qs
argument of tar_resources()
to specify optional settings for big data storage formats
powered by the qs
R package.
See the format
argument of tar_target()
for details.
Usage
tar_resources_qs(
compress_level = targets::tar_option_get("resources")$qs$compress_level,
shuffle = targets::tar_option_get("resources")$qs$shuffle,
nthreads = targets::tar_option_get("resources")$qs$nthreads,
preset = NULL
)
Arguments
compress_level |
Positive integer, |
shuffle |
|
nthreads |
Positive integer, number of threads to use for
functions in the |
preset |
Deprecated in |
Value
Object of class "tar_resources_qs"
, to be supplied
to the qs argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_repository_cas()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "qs",
resources = tar_resources(
qs = tar_resources_qs(preset = "fast")
)
)
Target resources for custom storage formats
Description
Create the repository_cas
argument of tar_resources()
to specify optional target settings for custom storage formats.
Usage
tar_resources_repository_cas(
envvars = targets::tar_option_get("resources")$repository_cas$envvars
)
Arguments
envvars |
Named character vector of environment variables.
These environment variables are temporarily set just before each call to
the storage methods you define in |
Details
tar_resources_repository_cas()
accepts
target-specific settings to customize tar_repository_cas()
storage
repositories.
Value
Object of class "tar_resources_repository_cas"
, to be supplied
to the repository_cas
argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_url()
Examples
# Somewhere in you target script file (usually _targets.R):
tar_target(
name = target_name,
command = data.frame(x = 1),
repository = tar_repository_cas(
upload = function(key, path) {
if (dir.exists(path)) {
stop("This CAS repository does not support directory outputs.")
}
if (!file.exists("cas")) {
dir.create("cas", recursive = TRUE)
}
file.copy(path, file.path("cas", key))
},
download = function(key, path) {
file.copy(file.path("cas", key), path)
},
exists = function(key) {
file.exists(file.path("cas", key))
}
),
resources = tar_resources(
repository_cas = tar_resources_repository_cas(
envvars = c(AUTHENTICATION_CREDENTIALS = "...")
)
)
)
Target resources: URL storage formats
Description
Create the url
argument of tar_resources()
to specify optional settings for URL storage formats.
See the format
argument of tar_target()
for details.
Usage
tar_resources_url(
handle = targets::tar_option_get("resources")$url$handle,
max_tries = targets::tar_option_get("resources")$url$max_tries,
seconds_interval = targets::tar_option_get("resources")$url$seconds_interval,
seconds_timeout = targets::tar_option_get("resources")$url$seconds_interval
)
Arguments
handle |
Object returned by |
max_tries |
Positive integer of length 1, maximum number of tries to access a URL. |
seconds_interval |
Nonnegative numeric of length 1,
number of seconds to wait between individual retries
while attempting to connect to the URL.
Use |
seconds_timeout |
Nonnegative numeric of length 1,
number of seconds to wait before timing out while trying to
connect to the URL.
Use |
Value
Object of class "tar_resources_url"
, to be supplied
to the url argument of tar_resources()
.
Resources
Functions tar_target()
and tar_option_set()
each takes an optional resources
argument to supply
non-default settings of various optional backends for data storage
and high-performance computing. The tar_resources()
function
is a helper to supply those settings in the correct manner.
In targets
version 0.12.2 and above, resources are inherited one-by-one
in nested fashion from tar_option_get("resources")
.
For example, suppose you set
tar_option_set(resources = tar_resources(aws = my_aws))
,
where my_aws
equals tar_resources_aws(bucket = "x", prefix = "y")
.
Then, tar_target(data, get_data()
will have bucket "x"
and
prefix "y"
. In addition, if new_resources
equals
tar_resources(aws = tar_resources_aws(bucket = "z")))
, then
tar_target(data, get_data(), resources = new_resources)
will use the new bucket "z"
, but it will still use the prefix "y"
supplied through tar_option_set()
. (In targets
0.12.1 and below,
options like prefix
do not carry over from tar_option_set()
if you
supply non-default resources to tar_target()
.)
See Also
Other resources:
tar_resources()
,
tar_resources_aws()
,
tar_resources_clustermq()
,
tar_resources_crew()
,
tar_resources_custom_format()
,
tar_resources_feather()
,
tar_resources_fst()
,
tar_resources_future()
,
tar_resources_gcp()
,
tar_resources_network()
,
tar_resources_parquet()
,
tar_resources_qs()
,
tar_resources_repository_cas()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
# Somewhere in you target script file (usually _targets.R):
tar_target(
name,
command(),
format = "url",
resources = tar_resources(
url = tar_resources_url(handle = curl::new_handle())
)
)
}
Get the tar_runtime
object.
Description
For internal purposes only. Not a user-side function. Do not invoke directly.
Usage
tar_runtime_object()
Details
Manages internal settings that targets need while they run.
Value
The internal tar_runtime
object of class "tar_runtime"
.
Examples
tar_runtime_object()
Write a target script file.
Description
The tar_script()
function is a convenient
way to create the required target script file (default: _targets.R
)
in the current working directory.
It always overwrites the existing target script,
and it requires you to be in the working directory
where you intend to write the file, so be careful.
See the "Target script" section for details.
Usage
tar_script(
code = NULL,
library_targets = TRUE,
ask = NULL,
script = targets::tar_config_get("script")
)
Arguments
code |
R code to write to the target script file.
If |
library_targets |
logical, whether to write a |
ask |
Logical, whether to ask before writing if the
target script file
already exists. If |
script |
Character of length 1, where to write
the target script file. Defaults to |
Value
NULL
(invisibly).
Target script file
Every targets
project requires a target script file.
The target script file is usually a file called _targets.R
Functions tar_make()
and friends look for the target script
and run it to set up the pipeline just prior to the main task.
Every target script file should run the following
steps in the order below:
Package: load the
targets
package. This step is automatically inserted at the top of the target script file produced bytar_script()
iflibrary_targets
isTRUE
, so you do not need to explicitly include it incode
.Globals: load custom functions and global objects into memory. Usually, this section is a bunch of calls to
source()
that run scripts defining user-defined functions. These functions support the R commands of the targets.Options: call
tar_option_set()
to set defaults for targets-specific settings such as the names of required packages. Even if you have no specific options to set, it is still recommended to calltar_option_set()
in order to register the proper environment.Targets: define one or more target objects using
tar_target()
.Pipeline: call
list()
to aggregate the targets from (4) into a list. Every target script file must return a pipeline object, which usually means ending with a call tolist()
. In practice, (4) and (5) can be combined together in the same function call.
See Also
Other scripts:
tar_edit()
,
tar_github_actions()
,
tar_helper()
,
tar_renv()
Examples
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script() # Writes an example target script file.
# Writes a user-defined target script:
tar_script({
library(targets)
library(tarchetypes)
x <- tar_target(x, 1 + 1)
tar_option_set()
list(x)
}, ask = FALSE)
writeLines(readLines("_targets.R"))
})
Deprecated: get the seed of the current target.
Description
Deprecated on 2023-10-12 (targets
version 1.3.2.9001).
Use tar_seed_get()
instead.
Usage
tar_seed(default = 1L)
Arguments
default |
Integer, value to return if |
Value
Integer of length 1. If invoked inside a targets
pipeline,
the return value is the seed of the target currently running,
which is a deterministic function of the target name. Otherwise,
the return value is default
.
Examples
tar_seed_get()
tar_seed_get(default = 123L)
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(returns_seed, tar_seed_get()), ask = FALSE)
tar_make()
tar_read(returns_seed)
})
}
Create a seed for a target.
Description
Create a seed for a target.
Usage
tar_seed_create(name, global_seed = NULL)
Arguments
name |
Character of length 1, target name. |
global_seed |
Integer of length 1, the overarching global
pipeline seed which governs the seeds of all the targets.
Set to |
Value
Integer of length 1, the target seed.
Seeds
A target's random number generator seed
is a deterministic function of its name and the global pipeline seed
from tar_option_get("seed")
. Consequently,
1. Each target runs with a reproducible seed so that different runs of the same pipeline in the same computing environment produce identical results. 2. No two targets in the same pipeline share the same seed. Even dynamic branches have different names and thus different seeds.
You can retrieve the seed of a completed target
with tar_meta(your_target, seed)
and run tar_seed_set()
on the result to locally
recreate the target's initial RNG state. tar_workspace()
does this automatically as part of recovering a workspace.
RNG overlap
In theory, there is a risk that the pseudo-random number generator
streams of different targets will overlap and produce statistically
correlated results. (For a discussion of the motivating problem,
see the Section 6: "Random-number generation" in the parallel
package vignette: vignette(topic = "parallel", package = "parallel")
.)
However, this risk is extremely small in practice, as shown by
L'Ecuyer et al. (2017) doi:10.1016/j.matcom.2016.05.005
under "A single RNG with a 'random' seed for each stream" (Section 4:
under "How to produce parallel streams and substreams").
targets
and tarchetypes
take the approach discussed in the
aforementioned section of the paper using the
secretbase
package by Charlie Gao (2024) doi:10.5281/zenodo.10553140.
To generate the 32-bit integer seed
argument of set.seed()
for each target, secretbase
generates a cryptographic hash using the
SHAKE256 extendable output function (XOF). secretbase
uses algorithms
from the Mbed TLS
C library.
References
Gao C (2024).
secretbase
: Cryptographic Hash and Extendable-Output Functions. R package version 0.1.0, doi:10.5281/zenodo.10553140.Pierre L'Ecuyer, David Munger, Boris Oreshkin, and Richard Simard (2017). Random numbers for parallel computers: Requirements and methods, with emphasis on GPUs. Mathematics and Computers in Simulation, 135, 3-17. doi:10.1016/j.matcom.2016.05.005.
See Also
Other pseudo-random number generation:
tar_seed_get()
,
tar_seed_set()
Get the random number generator seed of the target currently running.
Description
Get the random number generator seed of the target currently running.
Usage
tar_seed_get(default = 1L)
Arguments
default |
Integer, value to return if |
Value
Integer of length 1. If invoked inside a targets
pipeline,
the return value is the seed of the target currently running,
which is a deterministic function of the target name. Otherwise,
the return value is default
.
Seeds
A target's random number generator seed
is a deterministic function of its name and the global pipeline seed
from tar_option_get("seed")
. Consequently,
1. Each target runs with a reproducible seed so that different runs of the same pipeline in the same computing environment produce identical results. 2. No two targets in the same pipeline share the same seed. Even dynamic branches have different names and thus different seeds.
You can retrieve the seed of a completed target
with tar_meta(your_target, seed)
and run tar_seed_set()
on the result to locally
recreate the target's initial RNG state. tar_workspace()
does this automatically as part of recovering a workspace.
RNG overlap
In theory, there is a risk that the pseudo-random number generator
streams of different targets will overlap and produce statistically
correlated results. (For a discussion of the motivating problem,
see the Section 6: "Random-number generation" in the parallel
package vignette: vignette(topic = "parallel", package = "parallel")
.)
However, this risk is extremely small in practice, as shown by
L'Ecuyer et al. (2017) doi:10.1016/j.matcom.2016.05.005
under "A single RNG with a 'random' seed for each stream" (Section 4:
under "How to produce parallel streams and substreams").
targets
and tarchetypes
take the approach discussed in the
aforementioned section of the paper using the
secretbase
package by Charlie Gao (2024) doi:10.5281/zenodo.10553140.
To generate the 32-bit integer seed
argument of set.seed()
for each target, secretbase
generates a cryptographic hash using the
SHAKE256 extendable output function (XOF). secretbase
uses algorithms
from the Mbed TLS
C library.
References
Gao C (2024).
secretbase
: Cryptographic Hash and Extendable-Output Functions. R package version 0.1.0, doi:10.5281/zenodo.10553140.Pierre L'Ecuyer, David Munger, Boris Oreshkin, and Richard Simard (2017). Random numbers for parallel computers: Requirements and methods, with emphasis on GPUs. Mathematics and Computers in Simulation, 135, 3-17. doi:10.1016/j.matcom.2016.05.005.
See Also
Other pseudo-random number generation:
tar_seed_create()
,
tar_seed_set()
Examples
tar_seed_get()
tar_seed_get(default = 123L)
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(returns_seed, tar_seed_get()), ask = FALSE)
tar_make()
tar_read(returns_seed)
})
}
Set a seed to run a target.
Description
targets
generates its own target-specific seeds
using tar_seed_create()
. Use tar_seed_set()
to set one of
these seeds in R.
Usage
tar_seed_set(seed)
Arguments
seed |
Integer of length 1, value of the seed to set
with |
Details
tar_seed_set()
gives the user-supplied seed
to
set.seed()
and sets arguments kind = "default"
,
normal.kind = "default"
, and sample.kind = "default"
.
Value
NULL
(invisibly).
Seeds
A target's random number generator seed
is a deterministic function of its name and the global pipeline seed
from tar_option_get("seed")
. Consequently,
1. Each target runs with a reproducible seed so that different runs of the same pipeline in the same computing environment produce identical results. 2. No two targets in the same pipeline share the same seed. Even dynamic branches have different names and thus different seeds.
You can retrieve the seed of a completed target
with tar_meta(your_target, seed)
and run tar_seed_set()
on the result to locally
recreate the target's initial RNG state. tar_workspace()
does this automatically as part of recovering a workspace.
RNG overlap
In theory, there is a risk that the pseudo-random number generator
streams of different targets will overlap and produce statistically
correlated results. (For a discussion of the motivating problem,
see the Section 6: "Random-number generation" in the parallel
package vignette: vignette(topic = "parallel", package = "parallel")
.)
However, this risk is extremely small in practice, as shown by
L'Ecuyer et al. (2017) doi:10.1016/j.matcom.2016.05.005
under "A single RNG with a 'random' seed for each stream" (Section 4:
under "How to produce parallel streams and substreams").
targets
and tarchetypes
take the approach discussed in the
aforementioned section of the paper using the
secretbase
package by Charlie Gao (2024) doi:10.5281/zenodo.10553140.
To generate the 32-bit integer seed
argument of set.seed()
for each target, secretbase
generates a cryptographic hash using the
SHAKE256 extendable output function (XOF). secretbase
uses algorithms
from the Mbed TLS
C library.
References
Gao C (2024).
secretbase
: Cryptographic Hash and Extendable-Output Functions. R package version 0.1.0, doi:10.5281/zenodo.10553140.Pierre L'Ecuyer, David Munger, Boris Oreshkin, and Richard Simard (2017). Random numbers for parallel computers: Requirements and methods, with emphasis on GPUs. Mathematics and Computers in Simulation, 135, 3-17. doi:10.1016/j.matcom.2016.05.005.
See Also
Other pseudo-random number generation:
tar_seed_create()
,
tar_seed_get()
Examples
seed <- tar_seed_create("target_name")
seed
sample(10)
tar_seed_set(seed)
sample(10)
tar_seed_set(seed)
sample(10)
Show the cue-by-cue status of each target.
Description
For each target, report which cues are activated.
Except for the never
cue, the target will rerun in tar_make()
if any cue is activated. The target is suppressed if the never
cue is TRUE
. See tar_cue()
for details.
Usage
tar_sitrep(
names = NULL,
fields = NULL,
shortcut = targets::tar_config_get("shortcut"),
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
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")
)
Arguments
names |
Optional, names of the targets. If supplied, |
fields |
Optional, names of columns/fields to select. If supplied,
|
shortcut |
Logical of length 1, how to interpret the |
reporter |
Character of length 1, name of the reporter to user. Controls how messages are printed as targets are checked. The default of * `"balanced"`: a reporter that balances efficiency with informative detail. Uses a `cli` progress bar instead of printing messages for individual dynamic branches. To the right of the progress bar is a text string like "22.6s, 4510+, 124-" (22.6 seconds elapsed, 4510 targets detected as outdated so far, 124 targets detected as up to date so far). For best results with the balanced reporter, you may need to adjust your `cli` settings. See global options `cli.num_colors` and `cli.dynamic` at <https://cli.r-lib.org/reference/cli-config.html>. On that page is also the `CLI_TICK_TIME` environment variable which controls the time delay between progress bar updates. If the delay is too low, then overhead from printing to the console may slow down the pipeline. * `"terse"`: like `"balanced"`, except without a progress bar. * `"silent"`: print nothing. |
seconds_reporter |
Deprecated on 2025-03-31
( |
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
|
Details
Caveats:
-
tar_cue()
allows you to change/suppress cues, so the return value will depend on the settings you supply totar_cue()
. If a pattern tries to branches over a target that does not exist in storage, then the branches are omitted from the output.
-
tar_sitrep()
is myopic. It only considers what happens to the immediate target and its immediate upstream dependencies, and it makes no attempt to propagate invalidation downstream.
Value
A data frame with one row per target/object and one column
per cue. Each element is a logical to indicate whether the cue
is activated for the target.
See the field
argument in this help file for details.
See Also
Other inspect:
tar_deps()
,
tar_manifest()
,
tar_network()
,
tar_outdated()
,
tar_validate()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_sitrep()
tar_meta(starts_with("y_")) # see also any_of()
})
}
List skipped targets.
Description
List targets whose progress is "skipped"
.
Usage
tar_skipped(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
store |
Character of length 1, path to the
|
Value
A character vector of skipped targets.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_watch()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_skipped()
tar_skipped(starts_with("y_")) # see also any_of()
})
}
Run R scripts.
Description
Run all the R scripts in a directory in the environment specified.
Usage
tar_source(
files = "R",
envir = targets::tar_option_get("envir"),
change_directory = FALSE
)
Arguments
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. |
Details
tar_source()
is a convenient way to load R scripts
in _targets.R
to make custom functions available to the pipeline.
tar_source()
recursively looks for files ending
in .R
or .r
, and it runs each with
eval(parse(text = readLines(script_file, warn = FALSE)), envir)
.
Value
NULL
(invisibly)
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_store()
,
tar_unblock_process()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
# Running in tar_dir(), these files are written in tempdir().
dir.create("R")
writeLines("f <- function(x) x + 1", file.path("R", "functions.R"))
tar_script({
tar_source()
list(tar_target(x, f(1)))
})
tar_make()
tar_read(x) # 2
})
}
Deprecated: list started targets.
Description
Deprecated in favor of tar_dispatched()
on 2023-12-04
(targets
version 1.3.2.9004).
Usage
tar_started(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional, names of the targets. If supplied, the
output is restricted to the selected targets.
The object supplied to |
store |
Character of length 1, path to the
|
Value
A character vector of dispatched targets.
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
list(
tar_target(x, seq_len(2)),
tar_target(y, 2 * x, pattern = map(x))
)
}, ask = FALSE)
tar_make()
tar_dispatched()
tar_dispatched(starts_with("y_")) # see also any_of()
})
}
Deprecated: current data store path
Description
Deprecated: identify the file path to the data store of the pipeline currently running.
Usage
tar_store()
Details
tar_store()
was deprecated on 2022-10-11 (version 0.13.5.9000).
Use tar_path_store()
instead.
Value
Character, file path to the data store
of the pipeline currently running.
If called outside of the pipeline currently running,
tar_store()
returns tar_config_get("store")
.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_unblock_process()
Examples
tar_path_store()
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(tar_target(x, tar_path_store()), ask = FALSE)
store <- tempfile()
tar_make(store = store)
tar_read(x, store = store)
})
}
Declare a target.
Description
A target is a single step of computation in a pipeline. It runs an R command and returns a value. This value gets treated as an R object that can be used by the commands of targets downstream. Targets that are already up to date are skipped. See the user manual for more details.
tar_target()
defines a target using non-standard evaluation.
The name
argument is an unevaluated symbol,
and the command
and pattern
arguments are unevaluated expressions. Example:
tar_target(name = data, command = get_data())
.
tar_target_raw()
defines a target with standard evaluation.
The name
argument is a character string,
and the command
and pattern
arguments are evaluated expressions. Example:
tar_target_raw(name = "data", command = quote(get_data()))
.
tar_target_raw()
also has extra arguments deps
and string
for advanced customization.
Usage
tar_target(
name,
command,
pattern = NULL,
tidy_eval = targets::tar_option_get("tidy_eval"),
packages = targets::tar_option_get("packages"),
library = targets::tar_option_get("library"),
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_raw(
name,
command,
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")
)
Arguments
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 |
command |
R code to run the target.
In |
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 |
tidy_eval |
Logical, whether to enable tidy evaluation
when interpreting |
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 |
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 |
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 |
Value
A target object. Users should not modify these directly,
just feed them to list()
in your target script file
(default: _targets.R
).
Target objects
Functions like tar_target()
produce target objects,
special objects with specialized sets of S3 classes.
Target objects represent skippable steps of the analysis pipeline
as described at https://books.ropensci.org/targets/.
Please read the walkthrough at
https://books.ropensci.org/targets/walkthrough.html
to understand the role of target objects in analysis pipelines.
For developers, https://wlandau.github.io/targetopia/contributing.html#target-factories explains target factories (functions like this one which generate targets) and the design specification at https://books.ropensci.org/targets-design/ details the structure and composition of target objects.
Storage formats
targets
has several built-in storage formats to control how return
values are saved and loaded from disk:
-
"rds"
: Default, usessaveRDS()
andreadRDS()
. Should work for most objects, but slow. -
"auto"
: either"file"
or"qs"
, depending on the return value of the target. If the return value is a character vector of existing files (and/or directories), then the format becomes"file"
beforetar_make()
saves the target. Otherwise, the format becomes"qs"
.NOTE:
format = "auto"
slows down pipelines with 10000+ targets because it creates deep copies of 20000+ internal data objects. Pipelines of this size should use a more explicit format instead of"auto"
. -
"qs"
: Usesqs2::qs_save()
andqs2::qs_read()
. Should work for most objects, much faster than"rds"
. Optionally configure settings throughtar_resources()
andtar_resources_qs()
.Prior to
targets
version 1.8.0.9014,format = "qs"
used theqs
package.qs
has since been superseded in favor ofqs2
, and so later versions oftargets
useqs2
to save new data. To read existing data,targets
first attemptsqs2::qs_read()
, and then if that fails, it falls back onqs::qread()
. -
"feather"
: Usesarrow::write_feather()
andarrow::read_feather()
(version 2.0). Much faster than"rds"
, but the value must be a data frame. Optionally setcompression
andcompression_level
inarrow::write_feather()
throughtar_resources()
andtar_resources_feather()
. Requires thearrow
package (not installed by default). -
"parquet"
: Usesarrow::write_parquet()
andarrow::read_parquet()
(version 2.0). Much faster than"rds"
, but the value must be a data frame. Optionally setcompression
andcompression_level
inarrow::write_parquet()
throughtar_resources()
andtar_resources_parquet()
. Requires thearrow
package (not installed by default). -
"fst"
: Usesfst::write_fst()
andfst::read_fst()
. Much faster than"rds"
, but the value must be a data frame. Optionally set the compression level forfst::write_fst()
throughtar_resources()
andtar_resources_fst()
. Requires thefst
package (not installed by default). -
"fst_dt"
: Same as"fst"
, but the value is adata.table
. Deep copies are made as appropriate in order to protect against the global effects of in-place modification. Optionally set the compression level the same way as for"fst"
. -
"fst_tbl"
: Same as"fst"
, but the value is atibble
. Optionally set the compression level the same way as for"fst"
. -
"keras"
: superseded bytar_format()
and incompatible witherror = "null"
(intar_target()
ortar_option_set()
). Useskeras::save_model_hdf5()
andkeras::load_model_hdf5()
. The value must be a Keras model. Requires thekeras
package (not installed by default). -
"torch"
: superseded bytar_format()
and incompatible witherror = "null"
(intar_target()
ortar_option_set()
). Usestorch::torch_save()
andtorch::torch_load()
. The value must be an object from thetorch
package such as a tensor or neural network module. Requires thetorch
package (not installed by default). -
"file"
: A file target. To use this format, the target needs to manually identify or save some data and return a character vector of paths to the data (must be a single file path ifrepository
is not"local"
). (These paths must be existing files and nonempty directories.) Then,targets
automatically checks those files and cues the appropriate run/skip decisions if those files are out of date. Those paths must point to files or directories, and they must not contain characters|
or*
. All the files and directories you return must actually exist, or elsetargets
will throw an error. (And ifstorage
is"worker"
,targets
will first stall out trying to wait for the file to arrive over a network file system.) If the target does not create any files, the return value should becharacter(0)
.If
repository
is not"local"
andformat
is"file"
, then the character vector returned by the target must be of length 1 and point to a single file. (Directories and vectors of multiple file paths are not supported for file targets on the cloud.) That output file is uploaded to the cloud and tracked for changes where it exists in the cloud. As oftargets
version >= 1.11.0, the physical file is retained locally after the target runs. (Previous versions oftargets
deleted the file locally.) -
"url"
: An input URL. For this storage format,repository
is implicitly"local"
, URL format is likeformat = "file"
except the return value of the target is a URL that already exists and serves as input data for downstream targets. Optionally supply a customcurl
handle throughtar_resources()
andtar_resources_url()
. innew_handle()
,nobody = TRUE
is important because it ensurestargets
just downloads the metadata instead of the entire data file when it checks time stamps and hashes. The data file at the URL needs to have an ETag or a Last-Modified time stamp, or else the target will throw an error because it cannot track the data. Also, use extreme caution when trying to useformat = "url"
to track uploads. You must be absolutely certain the ETag and Last-Modified time stamp are fully updated and available by the time the target's command finishes running.targets
makes no attempt to wait for the web server. A custom format can be supplied with
tar_format()
. For this choice, it is the user's responsibility to provide methods for (un)serialization and (un)marshaling the return value of the target.The formats starting with
"aws_"
are deprecated as of 2022-03-13 (targets
version > 0.10.0). For cloud storage integration, use therepository
argument instead.
Formats "rds"
, "file"
, and "url"
are general-purpose formats
that belong in the targets
package itself.
Going forward, any additional formats should be implemented with
tar_format()
in third-party packages like tarchetypes
and geotargets
(for example: tarchetypes::tar_format_nanoparquet()
).
Formats "qs"
, "fst"
, etc. are legacy formats from before the
existence of tar_format()
, and they will continue to remain in
targets
without deprecation.
See Also
Other targets:
tar_cue()
Examples
# Defining targets does not run them.
data <- tar_target(target_name, get_data(), packages = "tidyverse")
analysis <- tar_target(analysis, analyze(x), pattern = map(x))
# In a pipeline:
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(name = x, command = 1 + 1),
tar_target_raw(name = "y", command = quote(x + y))
)
})
tar_make()
tar_read(x)
})
# Tidy evaluation
tar_option_set(envir = environment())
n_rows <- 30L
data <- tar_target(target_name, get_data(!!n_rows))
print(data)
# Disable tidy evaluation:
data <- tar_target(target_name, get_data(!!n_rows), tidy_eval = FALSE)
print(data)
tar_option_reset()
}
Test code in a temporary directory.
Description
Runs a test_that()
unit test inside a temporary
directory to avoid writing to the user's file space.
This helps ensure compliance with CRAN policies.
Also isolates tar_option_set()
options and environment variables specific to targets
and skips the test on Solaris.
Useful for writing tests for
targetopia packages
(extensions to targets
tailored to specific use cases).
Usage
tar_test(label, code)
Arguments
label |
Character of length 1, label for the test. |
code |
User-defined code for the test. |
Value
NULL
(invisibly).
See Also
Other utilities to extend targets:
tar_assert
,
tar_condition
,
tar_language
Examples
tar_test("example test", {
testing_variable_cafecfcb <- "only defined inside tar_test()"
file.create("only_exists_in_tar_test")
})
exists("testing_variable_cafecfcb")
file.exists("only_exists_in_tar_test")
Get the timestamp(s) of a target.
Description
Get the timestamp associated with a target's
last successful run.
tar_timestamp()
expects the name
argument to be an unevaluated
symbol, whereas tar_timestamp_raw()
expects name
to be a character string.
Usage
tar_timestamp(
name = NULL,
format = NULL,
tz = NULL,
parse = NULL,
store = targets::tar_config_get("store")
)
tar_timestamp_raw(
name = NULL,
format = NULL,
tz = NULL,
parse = NULL,
store = targets::tar_config_get("store")
)
Arguments
name |
Name of the target. If
|
format |
Deprecated in |
tz |
Deprecated in |
parse |
Deprecated in |
store |
Character string, directory path to the data store of the pipeline. |
Details
tar_timestamp()
checks the metadata in _targets/meta/meta
,
not the actual returned data of the target.
The timestamp depends on the storage format of the target.
If storage is local, e.g. formats like "rds"
and "file"
,
then the time stamp is the latest modification time
of the target data files at the time the target
last successfully ran. For non-local storage as with
repository = "aws"
and format = "url"
, targets
chooses instead
to simply record the time the target last successfully ran.
Value
If the target is not recorded in the metadata
or cannot be parsed correctly, then
tar_timestamp()
returns a POSIXct
object at 1970-01-01 UTC
.
See Also
Other time:
tar_newer()
,
tar_older()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
list(tar_target(x, 1))
}, ask = FALSE)
tar_make()
# Get the timestamp.
tar_timestamp(x)
# We can use the timestamp to cancel the target
# if it already ran within the last hour.
# Be sure to set `cue = tar_cue(mode = "always")`
# if you want the target to always check the timestamp.
tar_script({
list(
tar_target(
x,
tar_cancel((Sys.time() - tar_timestamp()) < 3600),
cue = tar_cue(mode = "always")
)
)}, ask = FALSE)
tar_make()
})
}
Choose code to run based on Target Markdown mode.
Description
Run one piece of code if Target Markdown mode interactive mode is turned on and another piece of code otherwise.
Usage
tar_toggle(interactive, noninteractive)
Arguments
interactive |
R code to run if Target Markdown interactive mode is activated. |
noninteractive |
R code to run if Target Markdown interactive mode is not activated. |
Details
Visit <books.ropensci.org/targets/literate-programming.html> to learn about Target Markdown and interactive mode.
Value
If Target Markdown interactive mode is not turned on,
the function returns the result of running the code.
Otherwise, the function invisibly returns NULL
.
See Also
Other Target Markdown:
tar_engine_knitr()
,
tar_interactive()
,
tar_noninteractive()
Examples
tar_toggle(
message("In interactive mode."),
message("Not in interactive mode.")
)
Get a target's traceback
Description
Return the saved traceback of a target.
Assumes the target errored out in a previous run of the pipeline
with workspaces enabled for that target.
See tar_workspace()
for details.
Usage
tar_traceback(
name,
envir = NULL,
packages = NULL,
source = NULL,
characters = NULL,
store = targets::tar_config_get("store")
)
Arguments
name |
Symbol, name of the target whose workspace to read. |
envir |
Deprecated in |
packages |
Logical, whether to load the required packages of the target. |
source |
Logical, whether to run the target script file
(default: |
characters |
Deprecated in |
store |
Character of length 1, path to the
|
Value
Character vector, the traceback of a failed target if it exists.
See Also
Other debug:
tar_load_globals()
,
tar_workspace()
,
tar_workspace_download()
,
tar_workspaces()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tmp <- sample(1)
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(workspace_on_error = TRUE)
list(
tar_target(x, "loaded"),
tar_target(y, stop(x))
)
}, ask = FALSE)
try(tar_make())
tar_traceback(y, characters = 60)
})
}
Unblock the pipeline process
Description
targets
tries to avoid running two concurrent instances
of tar_make()
on the same pipeline writing to the same data store.
Sometimes it generates false positives (meaning tar_make()
throws
this error even though there is only one instance of the pipeline
running.) If there is a false positive, tar_unblock_process()
gets the pipeline unstuck by removing the _targets/meta/process
file.
This allows the next call to tar_make()
to resume.
Usage
tar_unblock_process(store = targets::tar_config_get("store"))
Arguments
store |
Character string, path to the data store
(usually |
Value
NULL
(invisibly). Called for its side effects.
See Also
Other utilities:
tar_active()
,
tar_backoff()
,
tar_call()
,
tar_cancel()
,
tar_definition()
,
tar_described_as()
,
tar_envir()
,
tar_format_get()
,
tar_group()
,
tar_name()
,
tar_path()
,
tar_path_script()
,
tar_path_script_support()
,
tar_path_store()
,
tar_path_target()
,
tar_source()
,
tar_store()
Remove target script helper files.
Description
Remove target script helper files (default: _targets_r/
)
that were created by Target Markdown.
Usage
tar_unscript(script = targets::tar_config_get("script"))
Arguments
script |
Character of length 1, path to the
target script file. Defaults to |
Details
Target Markdown code chunks create R scripts in a folder
called _targets_r/
in order to aid the automatically supplied
_targets.R
file. Over time, the number of script files
starts to build up, and targets
has no way of automatically
removing helper script files that are no longer necessary.
To keep your pipeline up to date
with the code chunks in the Target Markdown document(s),
it is good practice to call tar_unscript()
at the beginning
of your first Target Markdown document. That way,
extraneous/discarded targets are automatically
removed from the pipeline when the document starts render.
If the target script is at some alternative path,
e.g. custom/script.R
, the helper scripts are in custom/script_r/
.
tar_unscript()
works on the helper scripts as long as your
project configuration settings correctly identify the correct
target script.
Value
NULL
(invisibly).
Examples
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_unscript()
})
Delete cloud object version IDs from local metadata.
Description
Delete version IDs from local metadata.
Usage
tar_unversion(
names = tidyselect::everything(),
store = targets::tar_config_get("store")
)
Arguments
names |
Tidyselect expression to identify the targets to drop
version IDs.
The object supplied to |
store |
Character of length 1, path to the
|
Value
NULL
(invisibly).
Cloud target data versioning
Some buckets in Amazon S3 or Google Cloud Storage are "versioned",
which means they track historical versions of each data object.
If you use targets
with cloud storage
(https://books.ropensci.org/targets/cloud-storage.html)
and versioning is turned on, then targets
will record each
version of each target in its metadata.
Functions like tar_read()
and tar_load()
load the version recorded in the local metadata,
which may not be the same as the "current" version of the
object in the bucket. Likewise, functions tar_delete()
and tar_destroy()
only remove
the version ID of each target as recorded in the local
metadata.
If you want to interact with the latest version of an object instead of the version ID recorded in the local metadata, then you will need to delete the object from the metadata.
Make sure your local copy of the metadata is current and up to date. You may need to run
tar_meta_download()
ortar_meta_sync()
first.Run
tar_unversion()
to remove the recorded version IDs of your targets in the local metadata.With the version IDs gone from the local metadata, functions like
tar_read()
andtar_destroy()
will use the latest version of each target data object.Optional: to back up the local metadata file with the version IDs deleted, use
tar_meta_upload()
.
See Also
Other clean:
tar_delete()
,
tar_destroy()
,
tar_invalidate()
,
tar_prune()
,
tar_prune_list()
Validate a pipeline of targets.
Description
Inspect the pipeline for issues and throw an error or warning if a problem is detected.
Usage
tar_validate(
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
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
|
Value
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.
See Also
Other inspect:
tar_deps()
,
tar_manifest()
,
tar_network()
,
tar_outdated()
,
tar_sitrep()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script(list(tar_target(x, 1 + 1)), ask = FALSE)
tar_validate()
})
}
visNetwork dependency graph.
Description
Visualize the pipeline dependency graph with a visNetwork
HTML widget.
Usage
tar_visnetwork(
targets_only = FALSE,
names = NULL,
shortcut = FALSE,
allow = NULL,
exclude = ".Random.seed",
outdated = TRUE,
label = targets::tar_config_get("label"),
label_width = targets::tar_config_get("label_width"),
level_separation = targets::tar_config_get("level_separation"),
degree_from = 1L,
degree_to = 1L,
zoom_speed = 1,
physics = FALSE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
targets_only |
Logical, whether to restrict the output to just targets
( |
names |
Names of targets. The graph visualization will operate
only on these targets (and unless |
shortcut |
Logical of length 1, how to interpret the |
allow |
Optional, define the set of allowable vertices in the graph.
Unlike |
exclude |
Optional, define the set of exclude vertices from the graph.
Unlike |
outdated |
Logical, whether to show colors to distinguish outdated
targets from up-to-date targets. (Global functions and objects
still show these colors.) Looking for outdated targets
takes a lot of time for large pipelines with lots of branches,
and setting |
label |
Character vector of one or more aesthetics to add to the
vertex labels. Can contain |
label_width |
Positive numeric of length 1, maximum width (in number of characters) of the node labels. |
level_separation |
Numeric of length 1,
|
degree_from |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
degree_to |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
zoom_speed |
Positive numeric of length 1, scaling factor on the zoom speed. Above 1 zooms faster than default, below 1 zooms lower than default. |
physics |
Logical of length 1, whether to implement interactive physics in the graph, e.g. edge elasticity. |
reporter |
Character of length 1, name of the reporter to user. Controls how messages are printed as targets are checked. The default of * `"balanced"`: a reporter that balances efficiency with informative detail. Uses a `cli` progress bar instead of printing messages for individual dynamic branches. To the right of the progress bar is a text string like "22.6s, 4510+, 124-" (22.6 seconds elapsed, 4510 targets detected as outdated so far, 124 targets detected as up to date so far). For best results with the balanced reporter, you may need to adjust your `cli` settings. See global options `cli.num_colors` and `cli.dynamic` at <https://cli.r-lib.org/reference/cli-config.html>. On that page is also the `CLI_TICK_TIME` environment variable which controls the time delay between progress bar updates. If the delay is too low, then overhead from printing to the console may slow down the pipeline. * `"terse"`: like `"balanced"`, except without a progress bar. * `"silent"`: print nothing. |
seconds_reporter |
Deprecated on 2025-03-31
( |
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
|
Value
A visNetwork
HTML widget object.
Dependency graph
The dependency graph of a pipeline is a directed acyclic graph (DAG)
where each node indicates a target or global object and each directed
edge indicates where a downstream node depends on an upstream node.
The DAG is not always a tree, but it never contains a cycle because
no target is allowed to directly or indirectly depend on itself.
The dependency graph should show a natural progression of work from
left to right. targets
uses static code analysis to create the graph,
so the order of tar_target()
calls in the _targets.R
file
does not matter. However, targets does not support self-referential
loops or other cycles. For more information on the dependency graph,
please read
https://books.ropensci.org/targets/targets.html#dependencies.
Storage access
Several functions like tar_make()
, tar_read()
, tar_load()
,
tar_meta()
, and tar_progress()
read or modify
the local data store of the pipeline.
The local data store is in flux while a pipeline is running,
and depending on how distributed computing or cloud computing is set up,
not all targets can even reach it. So please do not call these
functions from inside a target as part of a running
pipeline. The only exception is literate programming
target factories in the tarchetypes
package such as tar_render()
and tar_quarto()
.
See Also
Other visualize:
tar_glimpse()
,
tar_mermaid()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set()
list(
tar_target(y1, 1 + 1),
tar_target(y2, 1 + 1),
tar_target(z, y1 + y2, description = "sum of two other sums")
)
})
tar_visnetwork()
tar_visnetwork(allow = starts_with("y")) # see also any_of()
})
}
Shiny app to watch the dependency graph.
Description
Launches a background process with a Shiny app
that calls tar_visnetwork()
every few seconds.
To embed this app in other apps, use the Shiny module
in tar_watch_ui()
and tar_watch_server()
.
Usage
tar_watch(
seconds = 10,
seconds_min = 1,
seconds_max = 60,
seconds_step = 1,
targets_only = FALSE,
exclude = ".Random.seed",
outdated = FALSE,
label = NULL,
level_separation = 150,
degree_from = 1L,
degree_to = 1L,
config = Sys.getenv("TAR_CONFIG", "_targets.yaml"),
project = Sys.getenv("TAR_PROJECT", "main"),
height = "650px",
display = "summary",
displays = c("summary", "branches", "progress", "graph", "about"),
background = TRUE,
browse = TRUE,
host = getOption("shiny.host", "127.0.0.1"),
port = getOption("shiny.port", targets::tar_random_port()),
verbose = TRUE,
supervise = TRUE,
poll_connection = TRUE,
stdout = "|",
stderr = "|",
title = "",
theme = bslib::bs_theme(),
spinner = TRUE
)
Arguments
seconds |
Numeric of length 1, default number of seconds between refreshes of the graph. Can be changed in the app controls. |
seconds_min |
Numeric of length 1, lower bound of |
seconds_max |
Numeric of length 1, upper bound of |
seconds_step |
Numeric of length 1, step size of |
targets_only |
Logical, whether to restrict the output to just targets
( |
exclude |
Character vector of nodes to omit from the graph. |
outdated |
Logical, whether to show colors to distinguish outdated
targets from up-to-date targets. (Global functions and objects
still show these colors.) Looking for outdated targets
takes a lot of time for large pipelines with lots of branches,
and setting |
label |
Label argument to |
level_separation |
Numeric of length 1,
|
degree_from |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
degree_to |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
config |
Character of length 1, file path of the YAML
configuration file with |
project |
Character of length 1, name of the current
|
height |
Character of length 1,
height of the |
display |
Character of length 1, which display to show first. |
displays |
Character vector of choices for the display.
Elements can be any of
|
background |
Logical, whether to run the app in a background process so you can still use the R console while the app is running. |
browse |
Whether to open the app in a browser when the app is ready.
Only relevant if |
host |
Character of length 1, IPv4 address to listen on.
Only relevant if |
port |
Positive integer of length 1, TCP port to listen on.
Only relevant if |
verbose |
whether to print a spinner and informative messages.
Only relevant if |
supervise |
Whether to register the process with a supervisor. If |
poll_connection |
Whether to have a control connection to the process. This is used to transmit messages from the subprocess to the main process. |
stdout |
The name of the file the standard output of
the child R process will be written to.
If the child process runs with the |
stderr |
The name of the file the standard error of
the child R process will be written to.
In particular |
title |
Character of length 1, title of the UI. |
theme |
A call to |
spinner |
|
Details
The controls of the app are in the left panel.
The seconds
control is the number of seconds between
refreshes of the graph, and the other settings match
the arguments of tar_visnetwork()
.
Value
A handle to callr::r_bg()
background process running the app.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch_server()
,
tar_watch_ui()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
sleep_run <- function(...) {
Sys.sleep(10)
}
list(
tar_target(settings, sleep_run()),
tar_target(data1, sleep_run(settings)),
tar_target(data2, sleep_run(settings))
)
}, ask = FALSE)
# Launch the app in a background process.
tar_watch(seconds = 10, outdated = FALSE, targets_only = TRUE)
# Run the pipeline.
tar_make()
})
}
Create the full tar_watch()
app UI.
Description
Only exported for infrastructure purposes.
Not a user-side function. Users should instead
call tar_watch()
directly.
Usage
tar_watch_app_ui(
seconds,
seconds_min,
seconds_max,
seconds_step,
targets_only,
outdated,
label,
level_separation,
degree_from,
degree_to,
height,
display,
displays,
title,
theme,
spinner
)
Arguments
seconds |
Numeric of length 1, default number of seconds between refreshes of the graph. Can be changed in the app controls. |
seconds_min |
Numeric of length 1, lower bound of |
seconds_max |
Numeric of length 1, upper bound of |
seconds_step |
Numeric of length 1, step size of |
targets_only |
Logical, whether to restrict the output to just targets
( |
outdated |
Logical, whether to show colors to distinguish outdated
targets from up-to-date targets. (Global functions and objects
still show these colors.) Looking for outdated targets
takes a lot of time for large pipelines with lots of branches,
and setting |
label |
Label argument to |
level_separation |
Numeric of length 1,
|
degree_from |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
degree_to |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
height |
Character of length 1,
height of the |
display |
Character of length 1, which display to show first. |
displays |
Character vector of choices for the display.
Elements can be any of
|
title |
Character of length 1, title of the UI. |
theme |
A call to |
spinner |
|
Value
A Shiny UI.
Shiny module server for tar_watch()
Description
Use tar_watch_ui()
and tar_watch_server()
to include tar_watch()
as a Shiny module in an app.
Usage
tar_watch_server(
id,
height = "650px",
exclude = ".Random.seed",
config = Sys.getenv("TAR_CONFIG", "_targets.yaml"),
project = Sys.getenv("TAR_PROJECT", "main")
)
Arguments
id |
Character of length 1, ID corresponding to the UI function of the module. |
height |
Character of length 1,
height of the |
exclude |
Character vector of nodes to omit from the graph. |
config |
Character of length 1, file path of the YAML
configuration file with |
project |
Character of length 1, name of the current
|
Value
A Shiny module server.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_ui()
Shiny module UI for tar_watch()
Description
Use tar_watch_ui()
and tar_watch_server()
to include tar_watch()
as a Shiny module in an app.
Usage
tar_watch_ui(
id,
label = "tar_watch_label",
seconds = 10,
seconds_min = 1,
seconds_max = 60,
seconds_step = 1,
targets_only = FALSE,
outdated = FALSE,
label_tar_visnetwork = NULL,
level_separation = 150,
degree_from = 1L,
degree_to = 1L,
height = "650px",
display = "summary",
displays = c("summary", "branches", "progress", "graph", "about"),
title = "",
theme = bslib::bs_theme(),
spinner = FALSE
)
Arguments
id |
Character of length 1, ID corresponding to the UI function of the module. |
label |
Label for the module. |
seconds |
Numeric of length 1, default number of seconds between refreshes of the graph. Can be changed in the app controls. |
seconds_min |
Numeric of length 1, lower bound of |
seconds_max |
Numeric of length 1, upper bound of |
seconds_step |
Numeric of length 1, step size of |
targets_only |
Logical, whether to restrict the output to just targets
( |
outdated |
Logical, whether to show colors to distinguish outdated
targets from up-to-date targets. (Global functions and objects
still show these colors.) Looking for outdated targets
takes a lot of time for large pipelines with lots of branches,
and setting |
label_tar_visnetwork |
Character vector, |
level_separation |
Numeric of length 1,
|
degree_from |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
degree_to |
Integer of length 1. When you click on a node,
the graph highlights a neighborhood of that node. |
height |
Character of length 1,
height of the |
display |
Character of length 1, which display to show first. |
displays |
Character vector of choices for the display.
Elements can be any of
|
title |
Character of length 1, title of the UI. |
theme |
A call to |
spinner |
|
Value
A Shiny module UI.
See Also
Other progress:
tar_canceled()
,
tar_completed()
,
tar_dispatched()
,
tar_errored()
,
tar_poll()
,
tar_progress()
,
tar_progress_branches()
,
tar_progress_summary()
,
tar_skipped()
,
tar_watch()
,
tar_watch_server()
Load a locally saved workspace and seed for debugging.
Description
Load the packages, environment, and random number generator seed of a target.
Usage
tar_workspace(
name,
envir = parent.frame(),
packages = TRUE,
source = TRUE,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store")
)
Arguments
name |
Symbol, name of the target whose workspace to read. |
envir |
Environment in which to put the objects. |
packages |
Logical, whether to load the required packages of the target. |
source |
Logical, whether to run |
script |
Character of length 1, path to the
target script file. Defaults to |
store |
Character of length 1, path to the
|
Details
If you activate workspaces through the workspaces
argument
of tar_option_set()
, then under the circumstances you specify,
targets
will save a special workspace file to a location in
in _targets/workspaces/
. The workspace file is a compact reference
that allows tar_workspace()
to load the target's dependencies
and random number generator seed as long as the data objects
are still in the data store (usually files in _targets/objects/
).
When you are done debugging, you can remove the workspace files
using tar_destroy(destroy = "workspaces")
.
If tar_option_get("repository_meta")
is "aws"
or "gcp"
, then
tar_make()
uploads workspaces to the bucket and prefix provided.
Download one of these workspaces with tar_workspace_download()
.
Downloaded workspaces can be loaded the usual way with
tar_workspace()
, and you should see them in
character vector returned by tar_workspaces()
.
Value
This function returns NULL
, but it does load
the target's required packages, as well as multiple objects
into the environment (envir
argument) in order to replicate the
workspace where the error happened. These objects include
the global objects at the time tar_make()
was called and the
dependency targets. The random number generator seed for the
target is also assigned with tar_seed_set()
.
See Also
Other debug:
tar_load_globals()
,
tar_traceback()
,
tar_workspace_download()
,
tar_workspaces()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tmp <- sample(1)
tar_script({
library(targets)
library(tarchetypes)
list(
tar_target(x, "loaded"),
tar_target(y, stop(x))
)
}, ask = FALSE)
# The following code throws an error for demonstration purposes.
try(tar_make())
exists("x") # Should be FALSE.
tail(.Random.seed) # for comparison to the RNG state after tar_workspace(y)
tar_workspace(y)
exists("x") # Should be TRUE.
print(x) # "loaded"
# Should be different: tar_workspace() runs
# tar_seed_set(tar_meta(y, seed)$seed)
tail(.Random.seed)
})
}
Download a workspace from the cloud.
Description
Download a workspace file from the cloud
so it can be loaded with tar_workspace()
.
Usage
tar_workspace_download(
name,
script = targets::tar_config_get("script"),
store = targets::tar_config_get("store"),
verbose = TRUE
)
Arguments
name |
Symbol, name of the target whose workspace to download. |
script |
Character string, file path to the |
store |
Character of length 1, path to the
|
verbose |
|
Details
If tar_option_get("repository_meta")
is "aws"
or "gcp"
, then
tar_make()
uploads workspaces to the bucket and prefix provided.
Download one of these workspaces with tar_workspace_download()
.
Downloaded workspaces can be loaded the usual way with
tar_workspace()
, and you should see them in
character vector returned by tar_workspaces()
.
Value
NULL
(invisibly). Returns an error if the workspace
cannot be downloaded.
See Also
Other debug:
tar_load_globals()
,
tar_traceback()
,
tar_workspace()
,
tar_workspaces()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tmp <- sample(1)
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(
resources = tar_resources(
tar_resources_aws(
bucket = "YOUR_AWS_BUCKET",
prefix = "_targets"
)
),
repository = "aws",
repository_meta = "aws"
)
list(
tar_target(x, stop("this is an error and thus triggers a workspace"))
)
}, ask = FALSE)
# The following code throws an error for demonstration purposes.
try(tar_make())
# Say the workspace file for target x does not exist.
unlink("_targets/workspaces/x")
file.exists("_targets/workspaces/x")
# We can download it with tar_workspace_download()
tar_workspace_download(x)
file.exists("_targets/workspaces/x")
tar_workspace(x)
})
}
List locally saved target workspaces.
Description
List target workspaces currently saved to
_targets/workspaces/
locally.
Does not include workspaces saved to the cloud.
See tar_workspace()
and tar_workspace_download()
for more information.
Usage
tar_workspaces(names = NULL, store = targets::tar_config_get("store"))
Arguments
names |
Optional |
store |
Character of length 1, path to the
|
Value
Character vector of available workspaces to load with
tar_workspace()
.
See Also
Other debug:
tar_load_globals()
,
tar_traceback()
,
tar_workspace()
,
tar_workspace_download()
Examples
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
tar_script({
library(targets)
library(tarchetypes)
tar_option_set(workspace_on_error = TRUE)
list(
tar_target(x, "value"),
tar_target(y, x)
)
}, ask = FALSE)
tar_make()
tar_workspaces()
tar_workspaces(contains("x"))
})
}
Internal function to run a target on a worker.
Description
For internal purposes only. Not a user-side function.
Usage
target_run_worker(target, envir, path_store, fun, options, envvars)
Arguments
target |
A target object. |
envir |
An environment or the string |
path_store |
Character of length 1, path to the data store. |
fun |
Character of length 1, name of the user-side function called to run the pipeline. |
options |
List, exported from an object of class |
envvars |
Data frame of |
Use targets
Description
Set up targets
for an existing project.
Usage
use_targets(
script = targets::tar_config_get("script"),
open = interactive(),
overwrite = FALSE,
scheduler = NULL,
job_name = NULL
)
Arguments
script |
Character of length 1, where to write
the target script file. Defaults to |
open |
Logical of length 1, whether to open the file for editing in the RStudio IDE. |
overwrite |
Logical of length 1, |
scheduler |
Deprecated in |
job_name |
Deprecated in |
Details
use_targets()
writes an example _targets.R
script to
get started with a targets
pipeline for the current project.
Follow the comments in this script to adapt it as needed.
For more information, please visit
https://books.ropensci.org/targets/walkthrough.html.
Value
NULL
(invisibly).
See Also
Other help:
tar_reprex()
,
targets-package
,
use_targets_rmd()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
use_targets(open = FALSE)
})
}
Use targets with Target Markdown.
Description
Create an example Target Markdown report
to get started with targets
.
Usage
use_targets_rmd(path = "_targets.Rmd", open = interactive())
Arguments
path |
Character of length 1, output path of the Target Markdown report relative to the current active project. |
open |
Logical, whether to open the file for editing in the RStudio IDE. |
Value
NULL
(invisibly).
See Also
Other help:
tar_reprex()
,
targets-package
,
use_targets()
Examples
if (identical(Sys.getenv("TAR_INTERACTIVE_EXAMPLES"), "true")) {
tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
use_targets(open = FALSE)
})
}