How can one pipe a data frame to a function whose argument pipes a dot?
mpg %>% rbind(., . %>% rev())
Error in rep(xi, length.out = nvar) : attempt to replicate an object of type 'closure'
Another example:
mpg %>%
{
. %>% arrange(manufacturer)
}
Functional sequence with the following components:
- arrange(., manufacturer)
Use 'functions' to extract the individual functions.
What does the pipe do? The pipe operator, written as %>% , has been a longstanding feature of the magrittr package for R. It takes the output of one function and passes it into another function as an argument. This allows us to link a sequence of analysis steps.
A pipe function is a function that accepts a series of functions, which process an input parameter and return a output which will be the input for the next function.
And since R is a functional programming language, meaning that everything you do is basically built on functions, you can use the pipe operator to feed into just about any argument call. For example, we can pipe into a linear regression function and then get the summary of the regression parameters.
Wrap the dot to be piped in parentheses like (.)
:
mpg %>% rbind(., (.) %>% rev())
Or, for lambda function:
mpg %>%
{
(.) %>% arrange(manufacturer)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With