RE: [Rd] UseMethod call with no arguments - solved, I think

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 16 Nov 2004 - 23:36:29 EST

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 `further arguments'.

> 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
> fine.

> 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 ...

[1] "foo"
> bar(x=x) # arg is matched to x

[1] "foo"
> bar(1, x=x)

Error in bar(1, x) : no applicable method for "bar"
> bar <- function(y, x, ...) UseMethod("bar")
> bar(x) # matches y

[1] "foo"
> bar(x=x) # matches x

[1] "foo"

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
>
> Henrik
>
>
>> -----Original Message-----
>> From: r-devel-bounces@stat.math.ethz.ch
>> [mailto:r-devel-bounces@stat.math.ethz.ch] On Behalf Of
>> Henrik Bengtsson
>> Sent: Monday, November 15, 2004 7:54 PM
>> To: R-devel@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@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley@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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Nov 16 23:49:20 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:01:28 EST