x <- c(1:10, NA)
mean_c <- purrr::partial(mean, na.rm=TRUE)
mean_c(x)
mean_c(x,na.rm=FALSE) # it doesn't work
The last line of above code block doesn't work. It complains Error in mean.default(na.rm = TRUE, ...) : formal argument "na.rm" matched by multiple actual arguments.
Just like the default argument of normal function can be overwritten, the new function mean_c's default argument also needs to able to be overwritten.
The idea of purrr::partial() is to pre-fill in some arguments. If you want to be able to change na.rm from TRUE to FALSE why are you pre-filling in TRUE? You can just use the mean() function, unless I am missing something...
Partial doesn't change the defaults so much as it actually pre-fills in arguments. You should not pre-fill in any arguments for a function you may want to vary down the line. You can write a thin wrapper around a function if you just want to change the defaults. For example, if there is some function foo(a = 1, b = 2) and you want to change the default value for a...