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
somehow?

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

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to