Skip to content
Back to formatted view

Raw Message

Message-ID: <511ECE59.70608@gmail.com>
Date: 2013-02-16T00:10:01Z
From: Duncan Murdoch
Subject: Iterating through slots of an S4 object
In-Reply-To: <CAN5Vy720QMcVe8XNJje9Jc_8LcDY5ywcpWxy8GJiJz5QXW_THA@mail.gmail.com>

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.
>