hadley / adv-r

Advanced R: a book
http://adv-r.hadley.nz
Other
2.36k stars 1.71k forks source link

example 13.4.4(5) does not work as described for R 4.4.x #1788

Open JeffreyASmith opened 4 months ago

JeffreyASmith commented 4 months ago

R version 4.3.3 (2024-02-29 ucrt) -- "Angel Food Cake" 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 10

Same code and variables under R version 4.4.0 (2024-04-24 ucrt) -- "Puppy Cup" g(x) y 1 1

yeyuan98 commented 4 months ago

R NEWS stated this change effective for version 4.4.0

"UseMethod() no longer forwards local variables assigned in the generic function into method call environments before evaluating the method body. This makes method calls behave more like standard function calls and makes method code easier to analyze correctly."

https://cran.r-project.org/doc/manuals/r-release/NEWS.html