Warning about dim, nrow and ncol deprecated methods.
In the CAGEr package I use a SummarizedExperiment object to store DataFrames of Rle-encoded expression values. Updating the objects give warnings such as The dim() method for DataFrameList objects is deprecated. Please use dims() on these objects instead. Here is a minimal reproducible example.
> se <- SummarizedExperiment(assays=list(DataFrame()))
> assays(se)$foo <- DataFrame()
Warning messages:
1: The dim() method for DataFrameList objects is deprecated. Please use dims() on these objects instead.
2: The nrow() method for DataFrameList objects is deprecated. Please use nrows() on these objects instead.
3: The ncol() method for DataFrameList objects is deprecated. Please use ncols() on these objects instead.
4: The dim() method for DataFrameList objects is deprecated. Please use dims() on these objects instead.
5: The nrow() method for DataFrameList objects is deprecated. Please use nrows() on these objects instead.
6: The ncol() method for DataFrameList objects is deprecated. Please use ncols() on these objects instead.
You can also see the warnings in the CAGEr vignette.
This problem is also affecting us (BioC-devel 3.20, SummarizedExperiment_1.35.1): This triggers the warnings:
se <- SummarizedExperiment(assays = list(a = DataFrame(b = 1:3)))
assay(se, "a") <- DataFrame(b = 1:3)
but this does not:
se2 <- SummarizedExperiment(assays = list(a = matrix(1:3, ncol=1)))
assay(se2, "a") <- matrix(1:3, ncol = 1)
Maybe it's related to the assays class, which is SimpleDFrameList in the first, but SimpleList in the second example.
Is there any advice how to avoid it, other than using suppressWarnings(...)?
Looking a little bit closer, I think the deprecation happened here: https://github.com/Bioconductor/IRanges/commit/b4e9e7e8530a822980259c37cef186c652ba8be5
And in fact changing https://github.com/Bioconductor/SummarizedExperiment/blob/c5b7ca2f8d975af13a18b3b5931449f092657f5c/R/Assays-class.R#L107 to something like
if (is(assays, "DFrameList")) {
assays_dim <- dims(assays)
} else {
assays_dim <- dim(assays)
}
(which admittedly may not be the nicest or most future-proof solution, but works to pinpoint the source 🙂) already seems to get rid of the warnings.
The suppressWarnings() approach is also used elsewhere, e.g.: https://github.com/Bioconductor/S4Vectors/blob/40c18e5a3a5bc83898323e2c5bcac4dae6b92f60/R/DataFrame-class.R#L326-L331