loading...

Pipe operators. %>.% is a very simple and efficient pipe operator. %>_% is more complex. It forces conversion to a Flow object inside a pipeline and automatically manage non-standard evaluation through creation and unquoting of quosures for named arguments whose name ends with _.

x %>.% expr

x %>_% expr

debug_flow()

Arguments

x

Value or Flow object to pass to the pipeline.

expr

Expression to evaluation in the pipeline.

Details

With %>.%, the value must be explicitly indicated with a . inside the expression. The expression is not modified, but the value is first assigned into the calling environment as . (warning! possibly replacing any existing value... do not use . to name other objects). Also the expression is saved as .call in the calling environment so that debug_flow() can retrieve are rerun it easily. If a Flow object is used with %>.%, the .value is extracted from it into . first (and thus the Flow object is lost).

In the case of %>_% the Flow object is passed or created, it is also assigned in the calling environment as ... This can be used to refer to Flow object content within the pipeline expressions (e.g., ..$var).

For %>_%, the expression is reworked in such a way that a suitable lazyeval syntax is constructed for each variable whose name ends with _, and that variable is explicitly searched starting from ... Thus, x_ is replaced by !!..$x. For such variables appearing at left of an = sign, it is also replaced by := to keep correct R syntax (var_ = => !!..$var :=). This way, you just need to follow special variables by _, both in the flow() function arguments (to create quosures), and to the NSE expressions used inside the pipeline to get the job done! The raw expression is saved as .call_raw, while the reworked call is saved as .call for possible further inspection and debugging.

Finally, for %>_%, if expr is ., then, the last value from the pipe is extracted from the Flow object and returned. It is equivalent, thus, to flow_obj$.value.

You can mix %>.% and %>_% within the same pipeline. In case you use %>.% with a flow pipeline, it "unflows" it, extracting .value from the Flow object and further feeding it to the pipeline.

See also

Examples

# A simple pipeline with %>.% (explicit position of '.' required)
library(svFlow)
library(dplyr)
data(iris)
iris2 <- iris %>.%
  mutate(., log_SL = log(Sepal.Length)) %>.%
  filter(., Species == "setosa")

# The %>.% operator is much faster than magrittr's %>%
# (although this has no noticeable impact in most situations when the
# pipeline in used in an ad hoc way, outside of loops or other constructs
# that call it a larger number of times)