[Rd] Default subset and concatenation operators for namedList

Renaud Gaujoux renaud at mancala.cbio.uct.ac.za
Wed Jan 25 08:32:50 CET 2012


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



More information about the R-devel mailing list