Skip to contents

Replaces an existing pipeline step.

Usage

pipe_replace_step(
  pip,
  step,
  fun,
  params = list(),
  description = "",
  group = step,
  keepOut = FALSE
)

Arguments

pip

Pipeline object

step

string the name of the step. Each step name must be unique.

fun

function or name of the function to be applied at the step. Both existing and anonymous/lambda functions can be used. All function parameters must have default values. If a parameter is missing a default value in the function signature, alternatively, it can be set via the params argument (see Examples section with mean() function).

params

list list of parameters to set or overwrite parameters of the passed function.

description

string optional description of the step

group

string output collected after pipeline execution (see function pipe_collect_out()) is grouped by the defined group names. By default, this is the name of the step, which comes in handy when the pipeline is copy-appended multiple times to keep the results of the same function/step grouped at one place.

keepOut

logical if FALSE (default) the output of the step is not collected when calling pipe_collect_out() after the pipeline run. This option is used to only keep the results that matter and skip intermediate results that are not needed. See also function pipe_collect_out() for more details.

Value

returns the Pipeline object invisibly

See also

Examples

p <- pipe_new("pipe", data = 1)
pipe_add(p, "add1", \(x = ~data, y = 1) x + y)
pipe_add(p, "add2", \(x = ~data, y = 2) x + y)
pipe_add(p, "mult", \(x = 1, y = 2) x * y, keepOut = TRUE)
pipe_run(p) |> pipe_collect_out()
#> INFO  [2025-01-03 19:12:44.778] Start run of 'pipe' pipeline:
#> INFO  [2025-01-03 19:12:44.779] Step 1/4 data
#> INFO  [2025-01-03 19:12:44.782] Step 2/4 add1
#> INFO  [2025-01-03 19:12:44.783] Step 3/4 add2
#> INFO  [2025-01-03 19:12:44.785] Step 4/4 mult
#> INFO  [2025-01-03 19:12:44.786] Finished execution of steps.
#> INFO  [2025-01-03 19:12:44.787] Done.
#> $mult
#> [1] 2
#> 
pipe_replace_step(p, "mult", \(x = ~add1, y = ~add2) x * y, keepOut = TRUE)
pipe_run(p) |> pipe_collect_out()
#> INFO  [2025-01-03 19:12:44.790] Start run of 'pipe' pipeline:
#> INFO  [2025-01-03 19:12:44.791] Step 1/4 data - skip 'done' step
#> INFO  [2025-01-03 19:12:44.792] Step 2/4 add1 - skip 'done' step
#> INFO  [2025-01-03 19:12:44.793] Step 3/4 add2 - skip 'done' step
#> INFO  [2025-01-03 19:12:44.794] Step 4/4 mult
#> INFO  [2025-01-03 19:12:44.796] Finished execution of steps.
#> INFO  [2025-01-03 19:12:44.796] Done.
#> $mult
#> [1] 6
#> 
try(pipe_replace_step(p, "foo", \(x = 1) x))   # step 'foo' does not exist
#> Error : step 'foo' does not exist