| %>>% {lumberjack} | R Documentation |
The lumberjack operator
Description
The not-a-pipe operator that tracks changes in data.
Usage
lhs %>>% rhs
lhs %L>% rhs
Arguments
lhs |
Input value |
rhs |
Function call or 'dotted' expression (see below). as value |
Piping
The operators %L>% and %>>% are synonyms. The %L>%
is the default since version 0.3.0 to avoid confusion with the %>>%
operator of the pipeR package but %>>% still works.
The lumberjack operator behaves as a simplified version of the
magrittr pipe operator. The basic behavior of lhs %>>% rhs is
the following:
If the
rhsuses dot-variables (.), these are interpreted as the left-hand side, except in formulas where dots already have a special meaning.If the
rhsis a function call, with no dot-variables used, thelhsis used as its first argument.
The most notable differences with 'magrittr' are the following.
it does not allow you to define functions in the magrittr style, like
a <- . %>% sin(.)there is no assignment-pipe like
%<>%.you cannot do things like
x %>% sin(without the brackets).
Logging
If the left-hand-side is tagged for logging, the lumberjack will update the
log by calling the logger's $add() method, with arguments meta,
input, output. Here, meta is a list with information on
the operations performed, and input and output are the left-hand-side and the
result, respectively.
See Also
Other control:
dump_log(),
get_log(),
run_file(),
start_log(),
stop_log()
Examples
# pass arguments to a function
1:3 %L>% mean()
# pass arguments using "."
TRUE %L>% mean(c(1,NA,3), na.rm = .)
# pass arguments to an expression, using "."
1:3 %L>% { 3 * .}
# in a more complicated expression, return "." explicitly
women %L>% { .$height <- 2*.$height; . }