[Rd] Internally accessing ref class methods with .self$x is different from .self[['x']]
winstonchang1 at gmail.com
Wed Oct 16 23:12:18 CEST 2013
On Wed, Oct 16, 2013 at 3:41 PM, Gabriel Becker <gmbecker at ucdavis.edu> wrote:
> (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"
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))
More information about the R-devel