[Rd] class(<matrix>) |--> c("matrix", "arrary") [was "head.matrix ..."]
Hadley Wickham
h@w|ckh@m @end|ng |rom gm@||@com
Thu Nov 14 14:47:27 CET 2019
On Sun, Nov 10, 2019 at 2:37 AM Martin Maechler
<maechler using stat.math.ethz.ch> wrote:
>
> >>>>> Gabriel Becker
> >>>>> on Sat, 2 Nov 2019 12:37:08 -0700 writes:
>
> > I agree that we can be careful and narrow and still see a
> > nice improvement in behavior. While Herve's point is valid
> > and I understand his frustration, I think staying within
> > the matrix vs c(matrix, array) space is the right scope
> > for this work in terms of fiddling with inheritance.
>
> [.................]
>
>
> > > Also, we seem to have a rule that inherits(x, c) iff c %in% class(x),
> >
> > good point, and that's why my usage of inherits(.,.) was not
> > quite to the point. [OTOH, it was to the point, as indeed from
> > the ?class / ?inherits docu, S3 method dispatch and inherits
> > must be consistent ]
> >
> > > which would break -- unless we change class(x) to return the whole
> > set of inherited classes, which I sense that we'd rather not do....
>
> [................]
>
> > Note again that both "matrix" and "array" are special [see ?class] as
> > being of __implicit class__ and I am considering that this
> > implicit class behavior for these two should be slightly
> > changed ....
> >
> > And indeed I think you are right on spot and this would mean
> > that indeed the implicit class
> > "matrix" should rather become c("matrix", "array").
>
> I've made up my mind (and not been contradicted by my fellow R
> corers) to try go there for R 4.0.0 next April.
I can't seem to find the previous thread, so would you mind being a
bit more explicit here? Do you mean adding "array" to the implicit
class? Or adding it to the explicit class? Or adding it to inherits?
i.e. which of the following results are you proposing to change?
is_array <- function(x) UseMethod("is_array")
is_array.array <- function(x) TRUE
is_array.default <- function(x) FALSE
x <- matrix()
is_array(x)
#> [1] FALSE
x <- matrix()
inherits(x, "array")
#> [1] FALSE
class(x)
#> [1] "matrix"
It would be nice to make sure this is consistent with the behaviour of
integers, which have an implicit parent class of numeric:
is_numeric <- function(x) UseMethod("is_numeric")
is_numeric.numeric <- function(x) TRUE
is_numeric.default <- function(x) FALSE
x <- 1L
is_numeric(x)
#> [1] TRUE
inherits(x, "numeric")
#> [1] FALSE
class(x)
#> [1] "integer"
Hadley
--
http://hadley.nz
More information about the R-devel
mailing list