A description of this behavior can be found on the help page. ?UseMethod
UseMethod creates a new function call with arguments consistent as they appear. Any local variables defined before calling UseMethod are retained.
Thus, any local variables defined in the calling UseMethodfunction are passed to the next function in the form of local variables. You can see it with
g.numeric <- function(x) ls() #lists all variables in current environment
g(10)
# [1] "x" "y"
g.numeric(10)
# [1] "x"
source
share