Skip to contents

Non-standard-evaluation constructor mirroring targets::tar_target() for Rust: pass a bare name and unquoted pattern, for direct use in _targets.R. Compiles the #[extendr] functions in script with rextendr::rust_source() and calls them from the R post_script. Delegates to tar_target_rs_raw(); see it and run_rs_step() for the full reference. The Python/Julia twins are tar_target_py() / tar_target_jl().

Usage

tar_target_rs(
  name,
  script,
  post_script = NULL,
  inputs = NULL,
  output = "object",
  files = NULL,
  dependencies = NULL,
  features = NULL,
  profile = NULL,
  toolchain = NULL,
  pattern = NULL,
  packages = targets::tar_option_get("packages"),
  library = targets::tar_option_get("library"),
  deps = NULL,
  string = NULL,
  format = NULL,
  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, the target name (unquoted).

script

Path to the Rust script with #[extendr] functions (required). Either a literal string (an untracked path: editing the file does not invalidate the target) or a tar_target_path() reference to an upstream target (typically format = "file"), which makes this step re-run whenever that file changes.

post_script

Path to an R script run after compilation, where the compiled functions and inputs are in scope. Its last expression is the value (object mode); it returns file paths (file mode). Required for object mode. Accepts a literal string or a tar_target_path() reference, as for script.

inputs

Named character vector (or list) mapping the name seen inside the step (in the R environment and, after the hand-off, in the foreign session) to the name of an upstream target, e.g. c(x = "prepared_x"). Each upstream target becomes a dependency of this target and is bound by that name in the step environment; under dynamic branching the per-branch slice is bound instead.

output

Output mode: "object" (default) returns a converted R object, "file" returns a character vector of file paths (and defaults format to "file").

files

Optional character vector of file paths to return when no post_script is supplied in file mode.

dependencies, features, profile

Passed to rextendr::rust_source(): crate dependencies (named list), Cargo features, and build profile.

toolchain

Optional rustup toolchain (e.g. "stable-x86_64-pc-windows-gnu"); sets RUSTUP_TOOLCHAIN for the build.

pattern

Optional dynamic-branching pattern, unquoted (e.g. map(x)). Use tarpolyglot_map(x) to compile the crate once and reuse it across branches (see tarpolyglot_map()).

packages, library

Character vectors of R packages (and library paths) to load for the target, forwarded to targets::tar_target_raw().

deps, string

Advanced targets::tar_target_raw() arguments: extra dependency names and a string used for change detection.

format, repository, iteration

Storage/iteration settings forwarded to targets::tar_target_raw(). format defaults to "file" when output = "file", otherwise to the targets option default.

error, memory, garbage_collection, deployment, priority, resources, storage, retrieval, cue, description

Standard targets::tar_target_raw() execution/behaviour arguments, forwarded unchanged.

Value

A targets target object. When pattern uses tarpolyglot_map() it is instead a list of two targets: the <name>_rust_lib compile target and the branched <name> target.

Examples

if (FALSE) { # \dontrun{
list(
  tarpolyglot::tar_target_rs(
    name = rs_square,
    script = "scripts/square.rs",
    inputs = c(x = "value"),
    post_script = "scripts/post.R"
  )
)
} # }