[Rd] Change to I() in R 4.1
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Mon Oct 26 12:52:47 CET 2020
>
> Hi there,
> Is that change in R-devel intentional?
>
> library(Matrix)
> m <- as(matrix(c(0, 1)), "sparseMatrix")
>
> isS4(m)
> # [1] TRUE
>
> x <- I(m)
> # Warning message:
> # In `class<-`(x, unique.default(c("AsIs", oldClass(x)))) :
> # Setting class(x) to multiple strings ("AsIs", "dgCMatrix", ...);
> result will no longer be an S4 object
>
> isS4(x)
> # [1] FALSE
>
> This works fine in R 4.0.3 i.e. no warning and I() doesn't turn off the
> S4 bit of the object.
>
> This change breaks 17 Bioconductor packages.
>
> Seems that the culprit is this change in how I() is implemented:
>
> In R 4.0.3:
>
> > I
> function (x)
> {
> structure(x, class = unique(c("AsIs", oldClass(x))))
> }
>
> In R devel:
>
> > I
> function (x)
> `class<-`(x, unique.default(c("AsIs", oldClass(x))))
Yes, (by me), as I() was sticking out in the slowness bug PR#17794
https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17794
and the direct dangerous `call<-` will be replaced happily in
I()'s definition.
*But* as Luke Tierney had remarked to R-core, direct changing of
the class of an S4 object has given the above warning for a
quite while, (svn r47934 | jmc | 2009-02-17 )
*and* it has rather been an inconsistency in R, that you could
still use "low-level" means to change the class of an S4 object
to something invalid.
I really don't think people should be allowed to use I() to
change a valid S4 object into an invalid one, but this is what
happens (R 4.0.3 patched) :
> require(Matrix); M <- Matrix(0, 2,3); IM <- I(M)
> validObject(IM)
Error in .classEnv(classDef) :
trying to get slot "package" from an object of a basic class ("NULL") with no slots
> IM
----------- FAILURE REPORT --------------
--- failure: length > 1 in coercion to logical ---
--- srcref ---
:
--- package (from environment) ---
methods
--- call from context ---
showDefault(object)
--- call from argument ---
!is.null(clDef) && isS4(object) && is.na(match(clDef using className,
.BasicClasses))
--- R stacktrace ---
where 1: showDefault(object)
where 2: Error in showDefault(object) :
cannot get a slot ("slots") from an object of type "NULL"
>
> Unfortunately there is a bunch of code around that calls I() on S4
> objects, admittedly not necessarily for very good reasons, but it
> happens. Would it be possible that I() has a less destructive effect on
> S4 objects?
I'm not sure if this is really desirable... but I may fail to
see the point of allowing invalid I(<S4>) objects as they
appear in R 4.0.x ..
So what do you really propose that I(.) should be doing, e.g.,
for 'M' above ?
Martin
>
> Thanks,
> H.
>
> > sessionInfo()
> R Under development (unstable) (2020-10-17 r79346)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 20.04.1 LTS
>
> Matrix products: default
> BLAS: /home/biocbuild/bbs-3.13-bioc/R/lib/libRblas.so
> LAPACK: /home/biocbuild/bbs-3.13-bioc/R/lib/libRlapack.so
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] Matrix_1.2-18
>
> loaded via a namespace (and not attached):
> [1] compiler_4.1.0 grid_4.1.0 lattice_0.20-41
>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpages using fredhutch.org
> Phone: (206) 667-5791
> Fax: (206) 667-1319
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list