Can someone explain to me why the following two instructions have different outputs:
library(plyr)
library(dplyr)
ll <- list(a = mtcars, b = mtcars)
# using '.' as a function parameter
llply(ll, function(.) . %>% group_by(cyl) %>% summarise(min = min(mpg)))
# using 'd' as function parameter
llply(ll, function(d) d %>% group_by(cyl) %>% summarise(min = min(mpg)))
The first case, apparently, has not even been evaluated (which I understood with the help of spelling summarise: llply(ll, function(.) . %>% group_by(cyl) %>% sumamrise(min = min(mpg)))I would not have given an error).
So, this is related to the rules for determining the area and where things are evaluated, but I really want to understand what is happening and why it is happening? I use .as an argument in anonymous functions quite often, and I was puzzled to see the result.
In short, why .doesn't it work with %>%?
source
share