Just ran into this problem and made a reprex to figure it out. Wouldn't take much to turn it into a quick blog post about the value of purrr::partial().
library(purrr)
library(tidyr)
library(dplyr)
# NA-ify some populations
population[sample(seq_len(nrow(population)), 100), "population"] <- NA
This is a simple function abstracting a data processing pipe but where we want to pass the ... to a function used inside an anonymous function.
The ... are not what we think they are inside an anonymous function. If we create a partial function and pass the dots first, outside of the anonymous function, they get where they need to go.
Finally, this might also work because the dots aren’t inside an anonymous function, but it’s a little confusing or could be difficult to set up in more complicated situations.
Just ran into this problem and made a reprex to figure it out. Wouldn't take much to turn it into a quick blog post about the value of
purrr::partial()
.This is a simple function abstracting a data processing pipe but where we want to pass the
...
to a function used inside an anonymous function.This doesn’t work and it gives you a completely bonkers error message. Who said anything about
trim
?But you're convinced this should work because if you put
na.rm
in the pipe chain directly it works.The
...
are not what we think they are inside an anonymous function. If we create a partial function and pass the dots first, outside of the anonymous function, they get where they need to go.Finally, this might also work because the dots aren’t inside an anonymous function, but it’s a little confusing or could be difficult to set up in more complicated situations.