Try this: x...@y
On Thu, Feb 25, 2010 at 11:12 PM, Zhang,Yanwei <yanwei.zh...@cna.com> wrote: > > Dear all, > > I'm new to S4 classes and have a question on this. I want to use S4 because I > want to define explicitly the slots that the new class can have. But other > than that, the new class behaves exactly like a list. But this will not allow > me to use the generic functions that are already defined for class "list", > such as "$", "c", "[[", "names" or "length". > > For example, I defined a new class "abc", and tried to use "$", "length", and > "[[", but they do not work (which is shown below). I know I could define > these methods for the new class, but is there an easy way to allow this new > class to inherit all the functions that work for class "list"? I tried to > use contains="list", but this does not work either. Thanks for any help. > >> setClass("abc", representation(x="numeric",y="character",z="numeric")) > [1] "abc" >> xxx=new("abc",x=1,y="a",z=2) >> xxx$a > Error in xxx$a : $ operator not defined for this S4 class >> length(xxx) > [1] 1 >> xxx[[1]] > Error in xxx[[1]] : this S4 class is not subsettable > > > > Wayne (Yanwei) Zhang > Statistical Research > CNA > > > > > > NOTICE: This e-mail message, including any attachments and appended > messages, is for the sole use of the intended recipients and may contain > confidential and legally privileged information. > If you are not the intended recipient, any review, dissemination, > distribution, copying, storage or other use of all or any portion of this > message is strictly prohibited. > If you received this message in error, please immediately notify the sender > by reply e-mail and delete this message in its entirety. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.