pipe: Creates a pipe object out of a function and a list of...

Description Usage Arguments Details Value Examples

Description

Creates a pipe object out of a function and a list of arguments

Usage

1
pipe(.function, ...)

Arguments

.function

A function to repeat transformations from a trained pipeline on new data. Will be checked for being a function and taking a data argument.

...

Other arguments to .function. Non-named arguments are only accepted if .function takes a ... argument. Named arguments will be checked to be in the argument list of .function.

Details

Both .function and all ... arguments are force evaluated upon calling this function. This should guarantee that when calling this function in a clean environment, it will still be able to use the function and arguments. Any functions that .function depends on will most likely not be included, so library dependencies aren't taken into account here. The problem here lies in the fact that underlying functions in .function aren't automatically copied, but lazily evaluated. See the example for details.

Value

A pipe object with two entries:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# This example should work
dataset <- data.frame(x = 1:10, y= 1:10)
f <- function(data) data[1,]
saved_f <- pipe(.function = f)

without_removing_result <- invoke(saved_f, dataset)
rm(f)
with_removing_result <- invoke(saved_f, dataset)

# This example should fail
g <- function(data) data
f <- function(data) g(data)[1,]
saved_f <- pipe(.function = f)

without_removing_result <- invoke(saved_f, dataset)
rm(f, g)
# The following line will fail
# with_removing_result <- invoke(saved_f, dataset)

# The following is a work-around that currently should function
f <- function(data) {
  g <- function(data) data
  g(data)[1,]
}
saved_f <- pipe(.function = f)

without_removing_result <- invoke(saved_f, dataset)
rm(f)
with_removing_result <- invoke(saved_f, dataset)

jeroenvdhoven/datapiper documentation built on July 14, 2019, 9:34 p.m.