Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Gabor Grothendieck
On 5/23/07, hadley wickham <[EMAIL PROTECTED]> wrote: > On 5/23/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > On 5/23/07, Martin Maechler <[EMAIL PROTECTED]> wrote: > > > > "GaGr" == Gabor Grothendieck <[EMAIL PROTECTED]> > > > > on Wed, 23 May 2007 08:56:50 -0400 writes: > > >

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread hadley wickham
On 5/23/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 5/23/07, Martin Maechler <[EMAIL PROTECTED]> wrote: > > > "GaGr" == Gabor Grothendieck <[EMAIL PROTECTED]> > > > on Wed, 23 May 2007 08:56:50 -0400 writes: > > > >GaGr> On 5/23/07, Seth Falcon <[EMAIL PROTECTED]> wrote:

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Gabor Grothendieck
On 5/23/07, Martin Maechler <[EMAIL PROTECTED]> wrote: > > "GaGr" == Gabor Grothendieck <[EMAIL PROTECTED]> > > on Wed, 23 May 2007 08:56:50 -0400 writes: > >GaGr> On 5/23/07, Seth Falcon <[EMAIL PROTECTED]> wrote: >>> Andrew Clausen <[EMAIL PROTECTED]> writes: >>> >>> >

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Martin Maechler
> "GaGr" == Gabor Grothendieck <[EMAIL PROTECTED]> > on Wed, 23 May 2007 08:56:50 -0400 writes: GaGr> On 5/23/07, Seth Falcon <[EMAIL PROTECTED]> wrote: >> Andrew Clausen <[EMAIL PROTECTED]> writes: >> >> > Hi Seth, >> > >> > On Mon, May 21, 2007 at 05:15:10PM

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Gabor Grothendieck
On 5/23/07, Seth Falcon <[EMAIL PROTECTED]> wrote: > Andrew Clausen <[EMAIL PROTECTED]> writes: > > > Hi Seth, > > > > On Mon, May 21, 2007 at 05:15:10PM -0700, Seth Falcon wrote: > >> I will also add that the notion of a default argument on a generic > >> function seems a bit odd to me. If an arg

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Seth Falcon
Andrew Clausen <[EMAIL PROTECTED]> writes: > Hi Seth, > > On Mon, May 21, 2007 at 05:15:10PM -0700, Seth Falcon wrote: >> I will also add that the notion of a default argument on a generic >> function seems a bit odd to me. If an argument is available for >> dispatch, I just don't see what sense

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Gabor Grothendieck
# returns list(a1 = 1, a2 = 2, b = 3) with an attribute # "reshapeLong" containing skeleton (existing reshape also uses # "reshapeWide" and "reshapeLong" attributes) L <- list(a = 1:2, b = 3) long <- reshape(L, direction = "long") # returns original list but with an attribute "reshapeWide" resha

Re: [Rd] relist, an inverse operator to unlist

2007-05-23 Thread Andrew Clausen
Hi Gabor, Can you suggest some examples of how your proposal could be used? Reshape never returns a vector. Cheers, Andrew On Tue, May 22, 2007 at 07:36:56PM -0400, Gabor Grothendieck wrote: > One additional idea. > > I wonder if reshape might be promoted to a generic and relist made > into met

Re: [Rd] relist, an inverse operator to unlist

2007-05-22 Thread Gabor Grothendieck
One additional idea. I wonder if reshape might be promoted to a generic and relist made into methods for it. The unlisted version of an object would be the "long" version and the original version of the list would be the "wide" version. This would consolidate the two concepts together and make i

Re: [Rd] relist, an inverse operator to unlist

2007-05-22 Thread Martin Maechler
> "AndrewC" == Andrew Clausen <[EMAIL PROTECTED]> > on Tue, 22 May 2007 07:51:54 -0400 writes: AndrewC> Hi Seth, AndrewC> On Mon, May 21, 2007 at 05:15:10PM -0700, Seth Falcon wrote: >> I will also add that the notion of a default argument on a generic >> function seems

Re: [Rd] relist, an inverse operator to unlist

2007-05-22 Thread Andrew Clausen
Hi Seth, On Mon, May 21, 2007 at 05:15:10PM -0700, Seth Falcon wrote: > I will also add that the notion of a default argument on a generic > function seems a bit odd to me. If an argument is available for > dispatch, I just don't see what sense it makes to have a default. In > those cases, the d

Re: [Rd] relist, an inverse operator to unlist

2007-05-21 Thread Seth Falcon
Hi Andrew, Andrew Clausen <[EMAIL PROTECTED]> writes: > For reasons I can't explain, the code I posted worked in my session, but > didn't > work when I started a fresh one. standardGeneric() seems to get confused > by defaults for missing arguments. It looks for a "missing" method with > this c

Re: [Rd] relist, an inverse operator to unlist

2007-05-19 Thread Andrew Clausen
Hi all, For reasons I can't explain, the code I posted worked in my session, but didn't work when I started a fresh one. standardGeneric() seems to get confused by defaults for missing arguments. It looks for a "missing" method with this code: relist <- function(flesh, skeleton=attr(fle

Re: [Rd] relist, an inverse operator to unlist

2007-05-19 Thread Andrew Clausen
Hi all, I've written a new version of relist that includes the suggestions from Gabor and Martin: http://www.econ.upenn.edu/~clausen/computing/relist.R The leading example now looks like this: initial.param <- list(mean=c(0, 1), vcov=cbind(c(1, 1), c(1, 0))) initial.para

Re: [Rd] relist, an inverse operator to unlist

2007-05-14 Thread Martin Maechler
Nice ideas, Gabor and Andrew. While I agree with Andrew that such a utility makes for nicer and considerably better maintainable code in examples like his, and I do like to provide "inverse operator functions" in R whenever sensible, OTOH, we have strived to keep R's "base" package as lean and cle

Re: [Rd] relist, an inverse operator to unlist

2007-05-13 Thread Gabor Grothendieck
unlist would not attach a skeleton to every vector it returns, only the relist method of unlist would. That way just that method needs to be added and no changes to unlist itself are needed. Before applying unlist to an object you would coerce the object to class "relist" to force the relist met

Re: [Rd] relist, an inverse operator to unlist

2007-05-13 Thread Andrew Clausen
Hi Gabor, Thanks for the interesting suggestion. I must confess I got lost -- is it something like this? * unlist() could attach skeleton to every vector it returns. * relist() could then use the skeleton attached to the vector to reconstruct the object. The interface might be relist

Re: [Rd] relist, an inverse operator to unlist

2007-05-13 Thread Gabor Grothendieck
I suggest you define a "relist" class and then define an unlist method for it which stores the skeleton as an attribute. Then one would not have to specify skeleton in the relist command so relist(unlist(relist(x))) === x 1. relist(x) is the same as x except it gets an additional class "relist".

Re: [Rd] relist, an inverse operator to unlist

2007-05-13 Thread Andrew Clausen
On Sun, May 13, 2007 at 01:29:11PM -0400, Andrew Clausen wrote: > R has a function to convert complex objects into a vector > representation. This file provides an inverse operation called "unlist" to > convert vectors back to the convenient structural representation. Oops. I meant to say: R ha