[Rd] "for" loop wiht S4 Objects

From: Biczok Rudolf <r.biczok_at_dkfz-heidelberg.de>
Date: Fri, 23 Jan 2009 08:25:54 +0100

Hi all,  

I'm working with the S4-Class system and I have a little problem with

Implementing iteration functionality in my S4 class but it don't work:  

> setClass("foo",representation(bar="list"))

> x <- new("foo",bar=list(1,2,3))

>for(e in x) cat(e)

invalid type/length (S4/1) in vector allocation    

But when I extend from a primitive vector it works:  

> setClass("foo",contains="list")

> x <- new("foo",.Data=list(1,2,3))

>for(e in x) cat(e)


This is ok, but is there any other way to do this (for e.g. with a generic function)?  



        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 23 Jan 2009 - 17:41:47 GMT

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 Fri 23 Jan 2009 - 23:30:15 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