This is a helper for implementing additional pipes.

pipe_impl(pipe_left_arg, pipe_right_arg, pipe_environment, pipe_string = NULL)

Arguments

pipe_left_arg

possibily unevaluated left argument.

pipe_right_arg

possibly unevaluated right argument.

pipe_environment

environment to evaluate in.

pipe_string

character, name of pipe operator.

Value

result

Examples

# Example: how wrapr pipe is implemented print(`%.>%`)
#> function (pipe_left_arg, pipe_right_arg) #> { #> pipe_left_arg <- substitute(pipe_left_arg) #> pipe_right_arg <- substitute(pipe_right_arg) #> pipe_environment <- parent.frame() #> pipe_string <- as.character(sys.call()[[1]]) #> pipe_impl(pipe_left_arg, pipe_right_arg, pipe_environment, #> pipe_string) #> } #> <bytecode: 0x7fc757e03ca0> #> <environment: namespace:wrapr>
# Example: create a value that causes pipelines to record steps. # inject raw values into wrapped/annotated world unit_recording <- function(x, recording = paste(as.expression(substitute(x)), collapse = '\n')) { res <- list(value = x, recording = recording) class(res) <- "recording_value" res } # similar to bind or >>= # (takes U, f:U -> V to M(f(U)), instead of # U, f:U -> M(V) to M(f(U))) # so similar to a functor taking # f:U -> V to f':M(U) -> M(V) # followed by application. apply_left.recording_value <- function( pipe_left_arg, pipe_right_arg, pipe_environment, left_arg_name, pipe_string, right_arg_name) { force(pipe_environment) tmp <- wrapr::pipe_impl( pipe_left_arg = pipe_left_arg$value, pipe_right_arg = pipe_right_arg, pipe_environment = pipe_environment, pipe_string = pipe_string) unit_recording( tmp, paste0(pipe_left_arg$recording, ' %.>% ', paste(as.expression(pipe_right_arg), collapse = '\n'))) } # make available on standard S3 search path assign('apply_left.recording_value', apply_left.recording_value, envir = .GlobalEnv) unpack[value, recording] := 3 %.>% unit_recording(.) %.>% sin(.) %.>% cos(.) print(value)
#> [1] 0.9900591
print(recording)
#> [1] ". %.>% sin(.) %.>% cos(.)"
# clean up rm(envir = .GlobalEnv, list = 'apply_left.recording_value')