._ | R Documentation |
Pass first argument as dot to run code in second argument for pipe operators that do not natively support dot-replacement scheme (base R pipe operator)
._(x, expr)
x |
Object to pass to |
expr |
Expression to execute, containing |
The function has a side-effect to assign x
as .
and unevaluated expr
as .call
in the calling environment. Therefore, make sure you do not use .
or .call
there for something else. In case expr
fails in the middle of a series of chained pipes, you can inspect .
and .call
or possibly rerun a modified version of the instruction that failed on it for easier debugging purpose.
The result from executing expr
in the parent environment.
# The function is really supposed to be use in a pipe instruction
# This example only runs on R >= 4.1
## Not run:
# lm has data = as second argument, which does not fit well with the pipe |>
# In R 4.1, one should write:
iris |> \(.)(lm(data = ., Sepal.Length ~ Petal.Length + Species))()
# which is not very elegant ! With ._() it is more concise and straighforward
iris |> ._(lm(data = ., Sepal.Length ~ Petal.Length + Species))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.