I have the following snippet:
y <- 1
g <- function(x) {
y <- 2
UseMethod("g")
}
g.numeric <- function(x) y
g(10)
# [1] 2
I do not understand, why it is possible to have access to y
in g.numeric <- function(x) y
. To my understanding y's scope is just within the definition of the generic (g <- ...)
. Could anyone explain to me, how that is possible?