Nse function names

Hi,

You can use quosures to pass along variable names but what about function names?

For example, how would you write a function that spits out na.rm = T versions of other functions?

na_by_default_fun_factory <- function(function_name) {
#magical tidyeval happens here
}

> min_na.rm <- na_by_default_fun_factory(min)

> min_na.rm(c(1, NA, 2, 3))
1

Thanks!

Julien

You don't need tidyeval in this case, as far as I can tell.

na_by_default_fun_factory <- function(function_name) {
  purrr::partial(function_name, na.rm = TRUE)
}

min_na.rm <- na_by_default_fun_factory(min)
min_na.rm(c(1, NA, 2, 3))
#> [1] 1

max_na.rm <- na_by_default_fun_factory(max)
max_na.rm(c(1, NA, 2, 3))
#> [1] 3
2 Likes

Thank you @mishabalyasin! Exactly what I was looking for!
I really love this forum.

2 Likes