assign_into | R Documentation |
Assign into complex sub-expressions and return the whole object
assign_into(x, expr, value)
x |
The object to assign into. (Typically this argument is
delivered via |
expr |
The left hand side of the assignment operation to be
performed on |
value |
The right hand side of the assignment operation to be performed. |
The value of x
after performing the assignment.
As usual, x
, the object being passed in, should be
referenced in both expr
and value
as .
. In
fact, expr
*must* contain at least one .
, or else the
object will not be modified. (This is currently not checked.)
Note that this function uses the lazyeval package rather than its apparent successor, rlang, because rlang doesn't support interpolating expressions on the left-hand-side of an assignment operation: https://github.com/r-lib/rlang/issues/212.
%\>%
from the magrittr package.
library(magrittr) # Returns the entire list, not just the value of x list(a = 1, b = 2, c = 3) %>% assign_into(.$x, 5) ## Not run: # A more complex example of how this might be used in the middle of # a pipeline. Imagine that x is a list of SummarizedExperiment # objects, and for some reason one of the values in one of the # assays in one of the objects is wrong and needs to be modified. x %>% assign_into(assays(.[[1]])$counts[3,5], 45) %>% ... ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.