From renaud at mancala.cbio.uct.ac.za  Wed Jan 25 08:32:50 2012
From: renaud at mancala.cbio.uct.ac.za (Renaud Gaujoux)
Date: Wed, 25 Jan 2012 09:32:50 +0200
Subject: [Rd] Default subset and concatenation operators for namedList
Message-ID: <4F1FB022.3090809@cbio.uct.ac.za>

Hi,

in R version 2.14.1 (2011-12-22), is it wanted that the class namedList 
does not overloads the '[' and 'c' operators:

showMethods('c', class='namedList')
showMethods('[', class='namedList')

This means that if one creates a class that inherits from namedList, one 
has to define these operators so that they do not drop the S4 class 
(code below). I agree that one would probably have to define custom 
operators to correctly handle other possible extra slots when subsetting 
and concatenatiing. But it seems that namedList could at least deal with 
the slot `names` and not convert the object to a standard list, which is 
troublesome.

Is there a reason why these operators are not pre-defined in namedList?
Thank you.

Renaud

##########################
setClass('A', contains='namedList')
a <- new('A', list(a=1,b=2,c=3))
str(a)

# subset converts to standard list
str(a[1:2])
str(a[2:3])

# concatenation converts to standard list
str(c(a, list(d=4, e=5)))


-- 
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa



[Rd] Default subset and concatenation operators for namedList
Renaud Gaujoux