From ggrothendieck at gmail.com  Wed May 23 14:10:56 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 23 May 2007 08:10:56 -0400
Subject: [Rd] relist, an inverse operator to unlist
In-Reply-To: <20070523114617.GY28199@econ.upenn.edu>
References: <20070513172911.GP6923@econ.upenn.edu>
	<20070514043240.GL28199@econ.upenn.edu>
	<971536df0705132354u6e2ae0cci9b1e42a766dc0ec5@mail.gmail.com>
	<17992.5499.383704.358418@stat.math.ethz.ch>
	<20070519153636.GJ21178@econ.upenn.edu>
	<20070519160413.GK21178@econ.upenn.edu> <m2r6p990j5.fsf@ziti.local>
	<20070522115154.GS28199@econ.upenn.edu>
	<971536df0705221636r4c67b041mff2796836465ded5@mail.gmail.com>
	<20070523114617.GY28199@econ.upenn.edu>
Message-ID: <971536df0705230510i33dcdbd5s1d01e91564cc8961@mail.gmail.com>

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

reshape(long, direction = "wide")

In the last case there a new optional skeleton argument would be added.



On 5/23/07, Andrew Clausen <clausen at econ.upenn.edu> wrote:
> 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 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 it
> > easier to use since the user could leverage his knowledge of
> > how reshape works to lists where it would work analogously.
> >
> > Essentially reshape(myList, direction = "long") would be
> > similar to unlist but would add the attributes need to reverse
> > the procedure and reshape(myList, direction = "wide")
> > would perform the inversion.
> >
> > I am not sure if the reshape package has any bearing here
> > as well.
> >
> > On 5/22/07, Andrew Clausen <clausen at econ.upenn.edu> wrote:
> > >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 default should be handled by the method that has a
> > >> signature with said argument matching the "missing" class.
> > >>
> > >> What often does make sense is to define a generic function where some
> > >> argument are not available for dispatch.  For example:
> > >>
> > >> setGeneric("foo", signature="flesh",
> > >>            function(flesh, skeleton=attr(flesh, "skeleton")
> > >>                standardGeneric("foo")))
> > >
> > >That's an excellent suggestion.  Thanks!  However, I had to set the
> > >signature
> > >to c("numeric", "missing") rather than just "numeric".
> > >
> > >I have uploaded a new version here:
> > >
> > >       http://www.econ.upenn.edu/~clausen/computing/relist.R
> > >
> > >Cheers,
> > >Andrew
> > >
> > >______________________________________________
> > >R-devel at r-project.org mailing list
> > >https://stat.ethz.ch/mailman/listinfo/r-devel
> > >
>



[Rd] relist, an inverse operator to unlist
Gabor Grothendieck