From ggrothendieck at gmail.com  Sun May  8 02:20:15 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Sun May  8 02:20:23 2005
Subject: [Rd] Re: NextMethod problem
In-Reply-To: <971536df05050711507c5c9884@mail.gmail.com>
References: <971536df05050711507c5c9884@mail.gmail.com>
Message-ID: <971536df0505071720585a6510@mail.gmail.com>

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@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"
>


[Rd] Re: NextMethod problem
Gabor Grothendieck