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

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to