[Rd] UseMethod call with no arguments - solved, I think
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 16 13:36:29 CET 2004
On Tue, 16 Nov 2004, Henrik Bengtsson wrote:
> Hmmm, to follow up on my own question; it is likely that I have
> misunderstood the update note. Now, I read it as
> foo <- function(x, ...) UseMethod()
> is deprecated and that
That _is_ what it said.
> foo <- function(x, ...) UseMethod("foo", x)
> ( or foo <- function(x, ...) UseMethod("foo") )
> should be used.
> My concern/interpretation was that
> bar <- function(...) UseMethod("bar")
> is deprecated (where I saw "..." as the "arguments"). Reading ?UseMethod
I don't read that as being supported, and it does not work in S. `...' is
not strictly an argument of a function, and is usually documented as
> more carefully (it still says) - "If it is called with just one argument,
> the class of the first argument of the enclosing function is used as
> 'object': unlike S this is the actual argument passed and not the current
> value of the object of that name." - I see that the above should still be
> So, now the note makes perfectly sense and it is *not* a "big step".
However, removing undocumented features can happen at any time. There is
danger in using unusual constructions that may be allowed according to
some particular reading of some of the documentation. In particular,
consider the following
> bar <- function(..., x) UseMethod("bar")
> bar.foo <- function(..., x) print("foo")
> x <- structure(1, class="foo")
> bar(x) # arg is part of ...
> bar(x=x) # arg is matched to x
> bar(1, x=x)
Error in bar(1, x) : no applicable method for "bar"
> bar <- function(y, x, ...) UseMethod("bar")
> bar(x) # matches y
> bar(x=x) # matches x
and I don't think there is any intention that such behaviour will
necessarily continue (the last one does look like an error). The
rules seem not to be written down clearly enough.
> Best wishes
>> -----Original Message-----
>> From: r-devel-bounces at stat.math.ethz.ch
>> [mailto:r-devel-bounces at stat.math.ethz.ch] On Behalf Of
>> Henrik Bengtsson
>> Sent: Monday, November 15, 2004 7:54 PM
>> To: R-devel at r-project.org
>> Subject: [Rd] UseMethod call with no arguments
>> Dear R developers,
>> I will ask a very straightforward question concerning
>> UseMethod's future, because people depending on my code
>> wonder what will happen to it next.
>> In R v2.0.1 NEWS it says
>> o The undocumented use of UseMethod() with no argument is now
>> formally deprecated.
>> and in the R v2.0.1 help(UseMethod) it says
>> 'UseMethod' accepts a call with no arguments and tries to deduce
>> the generic from the context. This was undocumented on the help
>> page and is now deprecated. It is allowed but 'strongly
>> discouraged' in S-PLUS.
>> The short question is: UseMethod() with no arguments is
>> deprecated. Typically, after making something deprecated it
>> will later become defunct. Do you have any plans for when
>> this will happen? Are we talking months, years or in reality
>> never? A version number?
>> Second, in R v2.0.0 NEWS there was nothing on making
>> UseMethod() without arguments deprecated (the latest patched
>> version I have is dated October 21st). As I believe a rather
>> big step has been taken, I am somewhat surprised that I
>> haven't seen it discussed. Was there a discussion taking
>> place elsewhere that I missed, or is it an "obvious" update?
>> Finally, many thanks for making R (the software, the help,
>> the community,
>> ...) to what it is.
>> Best wishes
>> Henrik Bengtsson
>> Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
>> Lund Institute of Technology/Lund University, Sweden (+2h UTC)
>> +46 46 2229611 (off), +46 708 909208 (cell), +46 46 2224623 (fax)
>> h b @ m a t h s . l t h . s e, http://www.maths.lth.se/~hb/
>> R-devel at stat.math.ethz.ch mailing list
> R-devel at stat.math.ethz.ch mailing list
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel