[Rd] NextMethod and $.myclass

Gabor Grothendieck ggrothendieck at gmail.com
Fri Mar 16 18:54:45 CET 2007

The following redefines $ on "myclass" objects so that it looks up
the concatenation of the unevaluated second argument and 2
in the object and returns the result:

"$.myclass" <- function(x, name) x[[paste(substitute(name), 2, sep = "")]]

# test
myobject <- structure(list(x2 = 3), class = "myclass")
myobject$x # 3

The above worked as desired but now I want to rewrite $.myclass so that
it continues to work the same way but uses NextMethod
to get the next $ method where the remaining work is done. The problem
involves the fact that $ does not evaluate name.   Can this still be done

"$.myclass" <- function(x, name) {
    modified.name <- paste(substitute(name), 2, sep = "")
    # ???

More information about the R-devel mailing list