In fact, I'm almost certain that object.size
doesn't do what you want on S4
objects. Take a peek at the code for cgwtools::lssize
. Here's part of what I wrote, with a lot of help from other SO contributors:
fb4 <- function(x) {
if (isS4(x)) {
slots <- setNames(slotNames(x), slotNames(x))
lapply(lapply(slots, slot, object=x), fb4)
} else object.size(if(is.list(x)) unlist(x) else x)
}
fb4(object)
}
sizes<-sapply(items,function(k) sum(unlist(s4gonebyte(get(k))) ),simplify=FALSE)
That's a recursive dive into S4
slots and subslots.