Skip to contents

A new pipeline is always initialized with one 'data' step, which basically is a function returning the data.

Usage

pipe_new(name, data = NULL, logger = NULL)

Arguments

name

the name of the Pipeline

data

optional data used at the start of the pipeline. The data also can be set later using the pipe_set_data() function.

logger

custom logger to be used for logging. If no logger is provided, the default logger is used, which should be sufficient for most use cases. If you do want to use your own custom log function, you need to provide a function that obeys the following form:

function(level, msg, ...) { your custom logging code here }

The level argument is a string and will be one of info, warn, or error. The msg argument is a string containing the message to be logged. The ... argument is a list of named parameters, which can be used to add additional information to the log message. Currently, this is only used to add the context in case of a step giving a warning or error.

Note that with the default logger, the log layout can be altered any time via set_log_layout().

Value

returns the Pipeline object invisibly

Examples

data <- data.frame(x = 1:2, y = 3:4)
p <- pipe_new("myPipe", data = data)
p |> pipe_run() |> pipe_get_out("data")
#> INFO  [2025-01-03 19:12:43.584] Start run of 'myPipe' pipeline:
#> INFO  [2025-01-03 19:12:43.585] Step 1/1 data
#> INFO  [2025-01-03 19:12:43.586] Finished execution of steps.
#> INFO  [2025-01-03 19:12:43.587] Done.
#>   x y
#> 1 1 3
#> 2 2 4

# Setting data later
p <- pipe_new("myPipe")
pipe_get_data(p)
#> NULL

p <- pipe_set_data(p, data)
pipe_get_data(p)
#>   x y
#> 1 1 3
#> 2 2 4
p |> pipe_run() |> pipe_get_out("data")
#> INFO  [2025-01-03 19:12:43.594] Start run of 'myPipe' pipeline:
#> INFO  [2025-01-03 19:12:43.595] Step 1/1 data
#> INFO  [2025-01-03 19:12:43.596] Finished execution of steps.
#> INFO  [2025-01-03 19:12:43.596] Done.
#>   x y
#> 1 1 3
#> 2 2 4

# Initialize with custom logger
my_logger <- function(level, msg, ...) {
   cat(level, msg, "\n")
}
p <- pipe_new("myPipe", data = data, logger = my_logger)
p |> pipe_run() |> pipe_get_out("data")
#> info Start run of 'myPipe' pipeline: 
#> info Step 1/1 data 
#> info Finished execution of steps. 
#> info Done. 
#>   x y
#> 1 1 3
#> 2 2 4