SummarizedExperiment
SummarizedExperiment copied to clipboard
colData assignment should fail but does not
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.
Sounds reasonable. So to be precise, colData(se) <- DF:
- will throw an error if both
colnames(se)andrownames(DF)are not NULL and not identical. - will work and preserve the current colnames on
seifrownames(DF)is NULL. - will work and set the colnames on
se(torownames(DF)) ifcolnames(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.