6.3 Anonymous functions

If you don’t provide a name to a function

lapply(mtcars%>%select(mpg,cyl), function(x) length(unique(x)))
#> $mpg
#> [1] 25
#> 
#> $cyl
#> [1] 3
vector_len <- function(x) {
  length(unique(x))
}
lapply(mtcars%>%select(mpg,cyl), vector_len)
#> $mpg
#> [1] 25
#> 
#> $cyl
#> [1] 3

Invoking a function

args <- unique(coffee_ratings$species) %>% 
  `[[`(1) %>% 
  as.list()
  
  
  
do.call(avg_points, args)
#> # A tibble: 1 × 1
#>    mean
#>   <dbl>
#> 1  82.1