From jmc at research.bell-labs.com  Thu Sep  9 22:05:52 2004
From: jmc at research.bell-labs.com (John Chambers)
Date: Thu Sep  9 22:06:17 2004
Subject: [Rd] as(object,"list")  as(object,"matrix") differences?
References: <200409071617210704.0504144D@mail.math.fu-berlin.de>
	<413DD80C.2D5EA9C9@research.bell-labs.com>
	<200409081219020786.0B1B546F@mail.math.fu-berlin.de>
	<413F12EB.5F76BBA5@research.bell-labs.com>
	<200409092026400894.103612E2@mail.math.fu-berlin.de>
Message-ID: <4140B7A0.292B8ADA@research.bell-labs.com>

I did say the workaround was only a candidate!

Try changing the first line to:

setClass("listNamed",
         representation(names = "character"), contains = "list")

(because the automatically generated as() methods for further derived
classes, e.g. your Mlist,  will not copy the names unless that is an
explicit slot in the inherited class)

The workaround then does have the disadvantage that objects from it
_must_ have names, but then that was what we presumably wanted the
workaround for anyway.



Wolski wrote:
> 
> Hi!
> 
> Is this behaviour intended? Now no, nie, niente names are possible. Is this intended?
> Please run the sample code below.
> 
> R : Copyright 2004, The R Foundation for Statistical Computing
> Version 2.0.0 alpha (2004-09-09), ISBN 3-900051-07-0
> 
> setClass("listNamed", "list")
> setAs("listNamed", "list", function(from) {
>    if(strict) class(from) <- "list"
>    from
>    })
> 
> setMethod("show", "listNamed",
>           function(object) {
>               cat("An object of class ", class(object), "\n", sep="")
>               show(as(object, "list"))
>           })
> 
> 
>                                         #NAIVE inheritance from list.
>                                         #define cass
> 
> setClass("Mlist"
>          ,representation(info="character") #uniq names have to be unique?
>          ,contains="listNamed"
>          )
> 
> tmp <- as.list(1:4)
> names(tmp) <- letters[1:4]
> mylist<-new("Mlist" , tmp , info="numeric" )
> mylist
> 
> /E
> 
> Dipl. bio-chem. Eryk Witold Wolski             @    MPI-Moleculare Genetic
> Ihnestrasse 63-73 14195 Berlin                'v'
> tel: 0049-30-83875219                        /   \
> mail: witek96@users.sourceforge.net        ---W-W----
> http://r4proteomics.sourceforg.net

-- 
John M. Chambers                  jmc@bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc


[Rd] as(object,"list") as(object,"matrix") differences?
John Chambers