[R] deparse(substitute(x)) on an object with S3 class

Thomas Lumley tlumley at uw.edu
Thu May 3 22:21:44 CEST 2012


On Fri, May 4, 2012 at 2:02 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
> Note that print.testclass(testlist) also works as expected so it might
> be there's a forced evaluation somewhere inside S3 dispatch

Indeed. Without evaluating the argument, the S3 method dispatch can't
work out which method to dispatch to. In principle it could go back
and get a copy of the unevaluated promise, but it doesn't (and that
would only move the problem somewhere else, since the evaluation could
have side effects that would then happen multiple times)

Section 5.4 of the R Language Definition says, in part,

"When the method is invoked it is called with arguments that are the
same in number and have the same names as in the call to the generic.
They are matched to the arguments of the method according to the
standard R rules for argument matching. However the object, i.e. the
first argument has been evaluated."


   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland



More information about the R-help mailing list