[R] Iterating through slots of an S4 object

Duncan Murdoch murdoch.duncan at gmail.com
Sat Feb 16 01:10:01 CET 2013


On 13-02-15 6:14 PM, Scott Robinson wrote:
> I want to loop through slots of an S4 object and am unsure how to do so
> since the only way I can find to access them is individually in the form
> 'object at slotName'. I have guessed at a few possibilities which did not work
> and I have read some S4 object tutorials and things but still unsuccessful.

See ?slotNames.  For example,

for (slot in slotNames(x)) {
   cat(slot, ":\n")
   print(slot(x, slot))
}

Duncan Murdoch

>
> I presume it is possible though?
>
> Any help would be much appreciated,
>
> Scott
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list