[Rd] Re: NextMethod problem

Gabor Grothendieck ggrothendieck at gmail.com
Sun May 8 02:20:15 CEST 2005


Its probably obvious but just for completeness, I missed the
generic definition in pasting this into my post so I have
added it below:

On 5/7/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> Can anyone shed any light on what is going wrong here?
> Its based on simplifying some actual code that exists in
> model.frame.default.  It looks like a bug to me.  Thanks.
> 

function(x, ...) UseMethod("f")

> data(iris)
> 
> f.default <- function(x, subset, ...) {
>  subset <- eval(substitute(subset), iris, .GlobalEnv)
>  subset
> }
> 
> # This one is ok
> f(1, 1:3)
> 
> # putting an intermediate f.numeric in results in body
> # of subset function being returned
> f.numeric <- function(x, subset, ...) NextMethod("f")
> f(1, 1:3)
> 
> # slightly different f.numeric results in error
> f.numeric <- function(x, ...) NextMethod("f")
> f(1, 1:3)
> 
> R.version.string # Windows XP
> 
> ---
> 
> Output:

> function(x, ...) UseMethod("f")
> data(iris)
> 
> > f.default <- function(x, subset, ...) {
> +   subset <- eval(substitute(subset), iris, .GlobalEnv)
> +   subset
> + }
> >
> > # This one is ok
> > f(1, 1:3)
> [1] 1 2 3
> >
> >
> > # putting an intermediate f.numeric in results in body
> > # of subset function being returned
> > f.numeric <- function(x, subset, ...) NextMethod("f")
> > f(1, 1:3)
> function (x, ...)
> UseMethod("subset")
> <environment: namespace:base>
> >
> > # slightly different f.numeric results in error
> > f.numeric <- function(x, ...) NextMethod("f")
> > f(1, 1:3)
> Error in eval(expr, envir, enclos) : ..1 used in an incorrect context,
> no ... to look in
> >
> > R.version.string # Windows XP
> [1] "R version 2.1.0, 2005-04-18"
>



More information about the R-devel mailing list