Skip to contents

Validates pipeline against the pipelines bundled in package (see tar_archive_pipelines()), or name against the targets defined in a pipeline (see tar_manifest_archive()). Errors with a "did you mean" suggestion when the value doesn't match, so callers don't have to reimplement this check themselves.

Usage

tar_check_archive_pipeline(
  pipeline,
  package,
  envir = parent.frame(),
  arg_nm = rlang::caller_arg(pipeline),
  error_call = rlang::caller_env()
)

tar_check_archive_name(
  name,
  package,
  pipeline,
  envir = parent.frame(),
  arg_nm = rlang::caller_arg(name),
  error_call = rlang::caller_env()
)

Arguments

pipeline, name

A scalar character of the pipeline or target name to check.

package

A scalar character of the package name.

envir

An environment used to resolve package, so that a package currently loaded with pkgload::load_all() (e.g. during interactive package development) is resolved to its source directory instead of its installed one. Defaults to the calling environment.

arg_nm, error_call

Passed to rlang::arg_match0() to attribute the error to the correct argument and call.

Value

pipeline or name, invisibly, if valid. Otherwise, throws an error.

Details

tar_check_archive_name() reads the pipeline's target script in a callr subprocess, so anything the script does – such as calling targets::tar_option_set() or attaching packages – can't affect the caller's R session. This makes it safe to call from a function used in a user's own target script. The target names are cached for the rest of the session per version of package, so only the first check of each pipeline pays the subprocess startup cost. Checks run by the target script itself (e.g. when one data package's pipeline uses another's targets) are skipped while its names are read, so the cost doesn't grow with the nesting depth.

See also

tar_archive_pipelines() to list the pipelines in a package, and tar_manifest_archive() to list the targets within a pipeline.

Examples

tar_check_archive_pipeline("example-model", package = "tarchives")
#> [1] "example-model"

# \donttest{
withr::with_envvar(
  c(R_USER_CACHE_DIR = tempfile()),
  tar_check_archive_name(
    "data",
    package = "tarchives",
    pipeline = "example-model"
  )
)
#> [1] "data"
# }