[R] S4 non-virtual class with no slots?

Boylan, Ross Ross.Boylan at ucsf.edu
Fri Apr 22 22:38:57 CEST 2016

It seems that if an S4 class has no slots it can't be instantiated because it is assumed to be virtual.  Is there a way around this other than adding a do-nothing slot?  A singleton would be OK, though is not essential.

EmptyFitResult <- setClass("EmptyFitResult", representation=representation())
# also tried it without the second argument.  same result.
 > e <- EmptyFitResult()
 Error in new("EmptyFitResult", ...) :
   trying to generate an object from a virtual class ("EmptyFitResult")

This in R 3.1.1.

I fit simulated data; in some simulations none survive to the second stage of fitting.  So I just need a way to record that this happened, in a way that integrates with my other non-null results.

Ross Boylan

More information about the R-help mailing list