[Rd] NextMethod() and argument laziness

Davis Vaughan d@v|@ @end|ng |rom r@tud|o@com
Wed Aug 7 15:10:21 CEST 2019


Hi all, I'd like to ask if the following behavior is a bug. To me it
certainly feels surprising, at the very least. In this example, I would
like to call NextMethod() from my `child` object, have `cols` be left
untouched, and then substitute(cols) in the parent method. It works when
you use a `parent` object (as expected), but I would have also expected to
get `mpg` back when calling it from the `child` method.

my_generic <- function(x, cols) {
  UseMethod("my_generic")
}
my_generic.parent <- function(x, cols) {
  substitute(cols)
}
my_generic.child <- function(x, cols) {
  NextMethod()
}
obj_parent <- structure(mtcars, class = c("parent", class(mtcars)))
obj_child <- structure(obj_parent, class = c("child", class(obj_parent)))

my_generic(obj_parent, mpg)
#> mpg

my_generic(obj_child, mpg)
#> cols

Thanks,
Davis

	[[alternative HTML version deleted]]



More information about the R-devel mailing list