| %$>% | R Documentation |
%$>% construct operator allows taking apart the elements of a data to build
a new data type more quickly. This is done by data masking and access to the
original object by the . pronoun from magrittr. Each line is a component
of the new data. If the line is an assignment, the new component name is the
assigned variable name, otherwise, its position is determined by how many
previous variables have been assigned. See examples.
data %$>% code
data |
[R |
code |
[individual |
list with fields specified by any assignments inside code.
Other result assemblers:
%->%(),
%<-%(),
%to%(),
conserve(),
control()
# use the pipe to build data in steps:
testdf <- tibble::tribble(
~x, ~y,
3, 2,
5, 9,
12, 8
)
testdf %$>% {
minx <- min(x)
miny <- min(y)
minxy <- min(minx, miny)
}
# use the dot pronoun to refer to the entire data
c(5, 9, 10) %$>% {
min <- min(.)
max <- max(.)
whole <- .
}
# use curly braces for multiline instructions
testdf %$>% {
minxy <- {
minx <- min(x)
miny <- min(y)
min(minx, miny)
}
maxall <- max(.)
minall <- min(.)
}
# Result of unnamed instructions are used as is
testdf %$>% {
xval <- x
list(minx = min(x), miny = min(y), 12)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.