I am having some trouble converting my S4 object back into a list. Take for example, the following nested S4 classes:
setClass("nssItem",
representation(value = "numeric", text = "character", prefix = "character", type = "character"),
prototype(value = as.numeric(NA), text = as.character(NA), prefix = as.character(NA), type = as.character(NA))
)
setClass("geckoNss", representation(absolute = "character", item = "nssItem"))
An object of geckoNss
class contains objects of nssItem
class. Conceptually this seems like a list-like structure which allows for nesting.
Yet,
> temp <- new("nssItem")
> as.list(temp)
Error in as.list.default(temp) :
no method for coercing this S4 class to a vector
I understand this error, that is, I have not actually defined what as.list
means or how it applies with respect to the nssItem
class. Nonetheless, this seems like a very natural operation. How would I extend the definition of as.list
to all new classes I define?