SummarizedExperiment icon indicating copy to clipboard operation
SummarizedExperiment copied to clipboard

colData assignment should fail but does not

Open vjcitn opened this issue 5 years ago • 1 comments

library(SummarizedExperiment)
mymat = matrix((1:6)*1.0, nc=3)
dimnames(mymat) = list(c("A", "B"), letters[1:3])
se1 = SummarizedExperiment(mymat)
validObject(se1)
library(S4Vectors)
ndf = DataFrame(v1=10:12)
rownames(ndf) = letters[3:1]
ndf
colData(se1) = ndf 
newAa = assay(se1["A", "a"])
newAa
newAa == oldAa 

The content of the sample denoted a in the assay has changed through colData assignment. This seems incompatible with

297     \item{\code{colData(x)}, \code{colData(x) <- value}:}{Get or set the
298       column data. \code{value} is a \link{DataFrame} object. Row
299       names of \code{value} must be NULL or consistent with the existing
300       column names of \code{x}.}

in SummarizedExperiment-class.Rd. I propose that we tighten the "or consistent with" with "identical to" and throw an error in the code if that condition does not hold.

vjcitn avatar Feb 14 '20 15:02 vjcitn

Sounds reasonable. So to be precise, colData(se) <- DF:

  • will throw an error if both colnames(se) and rownames(DF) are not NULL and not identical.
  • will work and preserve the current colnames on se if rownames(DF) is NULL.
  • will work and set the colnames on se (to rownames(DF)) if colnames(se) is NULL.

The only worry is backward compatibility. This change together with the change discussed in issue #35 are likely to break existing code in various places. Hopefully it won't be too bad.

hpages avatar Feb 14 '20 15:02 hpages