There isn't really one. R will not normally search objects (non function objects) when looking for a function:
> mean(1:10)[1]5.5> mean <-1> mean(1:10)[1]5.5> rm(mean)> mean(1:10)[1]5.5
The examples shown by @Joris and @Sacha are where poor coding catches you out. One better way to write foo
is:
foo <-function(x, fun){
fun <- match.fun(fun)
fun(x)}
Which when used gives:
> foo(1:10, mean)[1]5.5> mean <-1> foo(1:10, mean)[1]5.5
There are situations where this will catch you out, and @Joris's example with na.omit
is one, which IIRC, is happening because of the standard, non-standard evaluation used in lm()
.