Advanced-R-Solutions
Advanced-R-Solutions copied to clipboard
UseMethod local variable update for R 4.4.0
Wondering if it's worth noting the update for R 4.4.0 here:
https://github.com/Tazinho/Advanced-R-Solutions/blob/cfdb2b5a09d6163f3888089e8ad9a2fa61b37989/13_S3.Rmd#L421
UseMethod creates a new function call with arguments matched as they came in to the generic. [Previously local variables defined before the call to UseMethod were retained; as of R 4.4.0 this is no longer the case.]
- https://stat.ethz.ch/R-manual/R-devel/library/base/html/UseMethod.html
Reprex
sessionInfo()
#> R version 4.5.0 (2025-04-11 ucrt)
#> ...
g <- function(x){
x <- 10
y <- 10
UseMethod('g')
}
g.default <- function(x) c(x = x, y = y)
x <- 1
y <- 1
g(x)
#> x y
#> 1 1
g.default(x)
#> x y
#> 1 1
rm(y)
g(x)
#> Error in g.default(x) : object 'y' not found