Question

I'm writing an S3 method that I want to work with any R object, including S4 objects.

The first thing I don't understand is that S4 classes don't appear to derive from an S4 base class, so given f <- function(x) UseMethod("f") I can't just declare an f.S4 dispatch method and have it pick up all S4 objects. (Although if you unclass an S4 object, it does seem to be given class S4.) How should I manage the dispatching?

It seems that the easiest way to deal with these S4 objects would be to convert them to be lists. Unfortunately, as.list throws an error ("no method for coercing this S4 class to a vector").

This is my test S4 object:

library(gWidgetstcltk)
win <- gwindow()

The functions S3Part and S3Class in the methods package looked promising, but they both throw errors when I use them on win. So, question 2 is: Is there a general way of converting S4 objects to lists?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top