Winston, Sounds like you might be better of constructing and evaluating an expression:
> test = setRefClass("test", methods = list(m1 = function() "hi", m2 = function() "lo", byname = function(nm) { + expr = substitute(.self$xXx(), list(xXx = nm)) + eval(expr) + })) > thing = test$new() > thing$byname("m1") [1] "hi" HTH, ~G On Wed, Oct 16, 2013 at 2:12 PM, Winston Chang <winstoncha...@gmail.com>wrote: > On Wed, Oct 16, 2013 at 3:41 PM, Gabriel Becker <gmbec...@ucdavis.edu> > wrote: > > Winston, > > > > (back on list since I found some official info) > > > > Looks like the behavior you are seeing is "documented-ish" > > > > Only methods actually used will be included in the environment > corresponding > > to an individual object. To declare that a method requires a particular > > other method, the first method should include a call to $usingMethods() > with > > the name of the other method as an argument. Declaring the methods this > way > > is essential if the other method is used indirectly (e.g., via sapply() > or > > do.call()). If it is called directly, code analysis will find it. > Declaring > > the method is harmless in any case, however, and may aid readability of > the > > source code. > > > > Seems like .self$usingMethods() is supposed to allow you to do what you > > want, but I wasn't able to get it to work after a few minutes of fiddling > > and the actual usingMethods method doesn't seem to do anything on cursory > > inspection in a toy example but I don't pretend to know the arcane > depths of > > the refclass machinery. > > > > I wasn't able to get .self$usingMethods() to work either. I think that > for my case, it still won't do the job - the issue is that I'm calling > a method and passing the name of another method, which is accessed via > [[. Since .self$usingMethods() supposedly analyzes code when the class > is installed (and not at runtime), that wouldn't help in this case. > > Previously I said that code like this would work, but I was wrong: > var <- "someMethod" > `$`(.self, var) > It doesn't work because $ doesn't evaluate var; it thinks you're > trying to get .self$var, not .self$someMethod. > > The workaround we're using for now is: > do.call(`$`, list(.self, var)) > > -Winston > -- Gabriel Becker Graduate Student Statistics Department University of California, Davis [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel