[R] Testing for S4 objects

John Fox jfox at mcmaster.ca
Fri Nov 26 04:28:50 CET 2004

Dear r-help list members,

Is there a way to test whether an object is an S4 object? The best that I've
been able to come up with is

	isS4object <- function(object) !(is.null(slotNames(object)))

which assumes that an S4 object has at least one slot. I think this is safe,
but perhaps I'm missing something.


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4

More information about the R-help mailing list