From winstonchang1 at gmail.com  Wed Oct 16 23:12:18 2013
From: winstonchang1 at gmail.com (Winston Chang)
Date: Wed, 16 Oct 2013 16:12:18 -0500
Subject: [Rd] Internally accessing ref class methods with .self$x is
 different from .self[['x']]
In-Reply-To: <CADwqtCOcyt5ePHH0fSdypPCqq34ndSMiiXNdeaDWw1WgWs=xDg@mail.gmail.com>
References: <CAFOpNVHwYJRXtwk0Y3v9RvFY9=B+na81MnCBHzMc2Y7SKBPekg@mail.gmail.com>
	<CADwqtCN1kEWcwZ_3ZUXvwPvjryWWkHgct9JjFuK3tjPJ0wKPkQ@mail.gmail.com>
	<CAFOpNVEv+1kQnS5g_zK0m--9v6K_M+CpAmq1RyPm3S967eFeRA@mail.gmail.com>
	<CADwqtCOcyt5ePHH0fSdypPCqq34ndSMiiXNdeaDWw1WgWs=xDg@mail.gmail.com>
Message-ID: <CAFOpNVG4e0L_eubbk+cZsaZcHgwqcmqZoeQ+Q=qkLCY1fLZUcQ@mail.gmail.com>

On Wed, Oct 16, 2013 at 3:41 PM, Gabriel Becker <gmbecker at 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



[Rd] Internally accessing ref class methods with .self$x is different from .self[['x']]
Winston Chang