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.