From Kurt.Hornik at wu-wien.ac.at  Thu Feb  5 09:05:24 2004
From: Kurt.Hornik at wu-wien.ac.at (Kurt Hornik)
Date: Thu Feb  5 09:05:56 2004
Subject: [Rd] Scoping bug in ftable() (PR#6541)
In-Reply-To: <e0n320tq4rov962q1gu4qjkik0hvd9lc1k@4ax.com>
References: <20040204183230.F3CFCEDDF@slim.kubism.ku.dk>
	<Pine.LNX.4.44.0402042108070.17491-100000@itasca2.stat.uiowa.edu>
	<e0n320tq4rov962q1gu4qjkik0hvd9lc1k@4ax.com>
Message-ID: <16417.63812.155132.669333@mithrandir.hornik.net>

>>>>> Duncan Murdoch writes:

> On Wed, 4 Feb 2004 21:21:35 -0600 (CST), Luke Tierney wrote:
>> On Wed, 4 Feb 2004 dmurdoch@pair.com wrote:
>>> I think the
>>> problem is in this line:
>>> 
>>> x <- do.call("table", c(as.list(substitute(list(...)))[-1],
>>> list(exclude = exclude)))

>  ...

>>> I think this works:
>>> 
>>> args <- list(...)
>>> names(args) <-
>>> as.character(unlist(as.list(substitute(list(...)))))[-1]
>        x <- do.call("table", c(args,list(exclude=exclude))  

> (which is what I committed, not what I wrote in the original message)
>>> 
>>> but isn't there an easier way?

> A much simpler way that probably does what was originally intended is
> this:

>  x <- table(..., exclude=exclude)

> This works fine on the example I posted.  Where it differs from my
> solution is when expressions are passed:

> It gives

>> x <- 1:2
>> y <- 3:4
>> ftable(x+1, y+1)
>    4 5
      
> 2  1 0
> 3  0 1

> whereas the current r-devel code gives

>> ftable(x+1, y+1)
>       y + 1 4 5
> x + 1          
> 2           1 0
> 3           0 1

> I like the new behaviour better, so I'll leave the complicated version
> in place.

Of course I longer recall the details but I think what I tried was
essentially to do table(..., exclude = exclude) in a way that would use
the table() heuristics for getting dimnames as if table() had been
called directly (rather than via ftable()).

Now the problem in what we currently have is that in the above:

R> x <- 1:2
R> y <- 3:4
R> ftable(z = x+1, y)
      y 3 4
x + 1      
2       1 0
3       0 1

and the first one should definitely be 'z' ... at least, according to my
original intentions :-)

And of course, pls note that we have

R> table(z=x+1, y+1)
   
z   4 5
  2 1 0
  3 0 1

in both r-release and r-devel so perhaps this is the problem we need to
fix first ...

Best
-k


[Rd] Scoping bug in ftable() (PR#6541)
Kurt Hornik