[Rd] Is it possible to simply the use of NULL slots (or at least improve the help files)?

Abby Spurdle @purd|e@@ @end|ng |rom gm@||@com
Thu Sep 24 22:50:44 CEST 2020


Hi Martin,
Thankyou for your response.

I suspect that we're not going to agree on the main point.
Making it trivially simple (as say Java) to set slots to NULL.
So, I'll move on to the other points here.

***Note that cited text uses excerpts only.***

>   setClassUnion("character_OR_NULL", c("character", "NULL"))
>   A = setClass("A", slots = c(x = "character_OR_NULL"))

I think the above construct needs to be documented much more clearly.
i.e. In the introductory and details pages for S4 classes.
This is something that many people will want to do.
And BasicClasses or NULL-class, are not the most obvious place to
start looking, either.

Also, I'd recommend the S4 authors, go one step further.
Include character_OR_NULL, numeric_OR_NULL, etc, or something similar,
in S4's predefined basic classes.
Otherwise, contributed packages will (eventually) end up with hundreds
of copies of these.

> setClassUnion("maybeNumber", c("numeric", "logical"))
> every instance of numeric _is_ a maybeNumber, e.g.,
> > is(1, "maybeNumber")
> [1] TRUE

> which I think is consistent with the use of 'superclass'

Not quite.

    x <- structure (sqrt (37), class = c ("sqrt.prime", "numeric") )
    is (x, "numeric") #TRUE
    is (x, "maybeNumber") #FALSE

So now, an object x, is a numeric but not a maybeNumber.
Perhaps a class union should be described as a partial imitation of a
superclass, for the purpose of making slots more flexible.


B.



More information about the R-devel mailing list