dot_arrow: Pipe operator ("dot arrow", "dot pipe" or "dot arrow pipe").

dot_arrowR Documentation

Pipe operator ("dot arrow", "dot pipe" or "dot arrow pipe").

Description

Defined as roughly : a %>.% b ~ { . <- a; b }; (with visible .-side effects).

Usage

pipe_left_arg %.>% pipe_right_arg

pipe_left_arg %>.% pipe_right_arg

pipe_left_arg %.% pipe_right_arg

Arguments

pipe_left_arg

left argument expression (substituted into .)

pipe_right_arg

right argument expression (presumably including .)

Details

The pipe operator has a couple of special cases. First: if the right hand side is a name, then we try to de-reference it and apply it as a function or surrogate function.

The pipe operator checks for and throws an exception for a number of "piped into nothing cases" such as 5 %.>% sin(), many of these checks can be turned off by adding braces.

For some discussion, please see https://win-vector.com/2017/07/07/in-praise-of-syntactic-sugar/. For some more examples, please see the package README https://github.com/WinVector/wrapr. For formal documentation please see https://github.com/WinVector/wrapr/blob/master/extras/wrapr_pipe.pdf. For a base-R step-debuggable pipe please try the Bizarro Pipe https://win-vector.com/2017/01/29/using-the-bizarro-pipe-to-debug-magrittr-pipelines-in-r/. %>.% and %.>% are synonyms.

The dot arrow pipe has S3/S4 dispatch (please see https://journal.r-project.org/archive/2018/RJ-2018-042/index.html). However as the right-hand side of the pipe is normally held unevaluated, we don't know the type except in special cases (such as the rigth-hand side being referred to by a name or variable). To force the evaluation of a pipe term, simply wrap it in .().

Value

eval({ . <- pipe_left_arg; pipe_right_arg };)

Functions

  • pipe_left_arg %.>% pipe_right_arg: dot arrow

  • pipe_left_arg %>.% pipe_right_arg: alias for dot arrow

  • pipe_left_arg %.% pipe_right_arg: alias for dot arrow

Examples


# both should be equal:
cos(exp(sin(4)))
4 %.>% sin(.) %.>% exp(.) %.>% cos(.)

f <- function() { sin }
# returns f() ignoring dot, not what we want
5 %.>% f()
# evaluates f() early then evaluates result with .-substitution rules
5 %.>% .(f())


wrapr documentation built on Aug. 20, 2023, 1:08 a.m.