tar_rep_index: Get overall rep index.

View source: R/tar_rep_index.R

tar_rep_indexR Documentation

Get overall rep index.

Description

Get the integer index of the current replication in certain target factories.

Usage

tar_rep_index()

Details

tar_rep_index() cannot run in your interactive R session or even the setup portion of ⁠_targets.R⁠. It must be part of the R command of a target actively running in a pipeline.

In addition, tar_rep_index() is only compatible with tar_rep(), tar_rep2(), tar_map_rep(), tar_map2_count(), and tar_map2_size(). In the latter 3 cases, tar_rep_index() cannot be part of the values or command1 arguments.

In tar_map_rep(), each row of the values argument (each "scenario") gets its own independent set of index values from 1 to batches * reps.

Value

Positive integer from 1 to batches * reps, index of the current replication in an ongoing pipeline.

Examples

if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
targets::tar_script({
  tar_map_rep(
    x,
    data.frame(index = tar_rep_index()),
    batches = 2L,
    reps = 3L,
    values = list(value = c("a", "b"))
  )
})
targets::tar_make()
x <- targets::tar_read(x)
all(x$index == x$tar_rep + (3L * (x$tar_batch - 1L)))
#> TRUE
})
}

wlandau/tarchetypes documentation built on April 11, 2025, 11:47 p.m.