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

Boylan, Ross Ross.Boylan at ucsf.edu
Sat Apr 23 02:33:15 CEST 2016


Thanks, Martin, that (inherit from a virtual class) worked great.  I already had a base class created with setUnion, and so this was an easy switch.

I had assumed that since inheriting from a class without slots would produce a class without slots the result would still be virtual.  Fortunately that's not the case.

Ross
________________________________________
From: Martin Morgan [martin.morgan at roswellpark.org]
Sent: Friday, April 22, 2016 2:36 PM
To: Boylan, Ross; r-help at r-project.org
Subject: Re: [R] S4 non-virtual class with no slots?

On 04/22/2016 04:38 PM, Boylan, Ross wrote:
> 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.
>
> Problem:
> 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.
>
> Context:
> 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.
>

A not too artificial solution is to create a base class, with derived
classes corresponding to stateless or stateful conditions

Base = setClass("Base"); A = setClass("A", contains="Base"); A()

Martin Morgan

> Thanks.
> Ross Boylan
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


This email message may contain legally privileged and/or confidential information.  If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited.  If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.



More information about the R-help mailing list