Skip to content

UseMethod local variable update for R 4.4.0 #293

@epi-sam

Description

@epi-sam

Wondering if it's worth noting the update for R 4.4.0 here:

But when we call `g(x)` we get `c(1, 10)`:

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.]

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions