flow | R Documentation |
Flow objects, as explicitly created by flow()
, or implicitly by the
%>_%
pipe operator are proto objects (class-less objects
with possible inheritance) that can be combined nicely with pipelines using
the specialized flow pipe operator %>_%
(or by using $
).
They allow for encapsulating satellite objects/variables related to the
pipeline, and they deal with non-standard evaluations using the tidyeval
mechanism automatically with minimal changes required by the user.
flow(. = NULL, .value = NULL, ...)
enflow(.value, env = caller_env(), objects = ls(env))
is.flow(x)
is_flow(x)
as.flow(x, ...)
as_flow(x, ...)
## S3 method for class 'Flow'
x$name
## S3 replacement method for class 'Flow'
x$name <- value
. |
If a Flow object is provided, inherit from it, otherwise,
create a new Flow object inheriting from |
.value |
The pipe value to pass to the object (used instead of |
... |
For |
env |
The environment to use for populating the Flow object. All
objects from this environment are injected into it, with the objects not
starting with a dot and ending with an underscore ( |
objects |
A character string with the name of the objects from |
x |
An object (a Flow object, or anything to test if it is a
Flow object in |
name |
The name of the item to get from a Flow object. If |
value |
The value or expression to assign to |
enflow()
creates a Flow object in the head of a "flow pipeline" in the
context of a functional sequence, that is a function that converts an
ad hoc, single use pipeline into a function reusable in a different
context. Satellite data become arguments of the function.
When a Flow object is created from scratch, it always inherits
from .GlobalEnv
, no matter where the expression was executed (in fact, it
inherits from an empty root Flow object itself inheriting from
.GlobalEnv
). This is a deliberate design choice to overcome some
difficulties and limitations of proto objects, see proto()
.
enflow()
creates a Flow object and populates it automatically with all
the objects that are present in env=
(by default, the calling environment).
It is primarily intended to be used inside a function, as first instruction
of a "flow pipeline". Hence, it collects all function arguments inside that
pipeline in a most convenient way.
str.Flow, quos_underscore, %>_%
library(svFlow)
library(dplyr)
data(iris)
foo <- function(data, x_ = Sepal.Length, y_ = log_SL,
fun_ = mean, na_rm = TRUE)
enflow(data) %>_%
mutate(., y_ = log(x_)) %>_%
summarise(., fun_ = fun_(y_,
na.rm = na_rm_)) %>_% .
foo(iris)
foo(iris, x_ = Petal.Width)
foo(iris, x_ = Petal.Width, fun_ = median)
# Unfortunately, this does not work, due to limitations of tidyeval's :=
#foo(iris, x_ = Petal.Width, fun_ = stats::median)
foo2 <- function(., x_ = Sepal.Length, y_ = log_SL, na_rm = TRUE)
enflow(.)
foo2
foo2(1:10) -> foo_obj
ls(foo_obj)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.