[Rd] Default subset and concatenation operators for namedList

From: Renaud Gaujoux <renaud_at_mancala.cbio.uct.ac.za>
Date: Wed, 25 Jan 2012 09:32:50 +0200


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_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 25 Jan 2012 - 07:37:16 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 Jan 2012 - 15:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive