Skip to content

Commit

Permalink
Fix recent regression in mcols() setter
Browse files Browse the repository at this point in the history
The regression was introduced at commit 05a99cd and it breaks the mcols()
setter when the right value is a zero-column ordinary data frame.
This affected several Bioconductor software packages: Gviz, chimeraviz,
rtracklayer, AllelicImbalance, ORFik, and a few others...
  • Loading branch information
hpages committed Oct 2, 2019
1 parent b77f347 commit e53a50d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: The S4Vectors package defines the Vector and List virtual classes
interest (e.g. DataFrame, Rle, and Hits) are implemented in the
S4Vectors package itself (many more are implemented in the IRanges
package and in other Bioconductor infrastructure packages).
Version: 0.23.24
Version: 0.23.25
Encoding: UTF-8
Author: H. Pagès, M. Lawrence and P. Aboyoun
Maintainer: Bioconductor Package Maintainer <maintainer@bioconductor.org>
Expand Down
43 changes: 29 additions & 14 deletions R/DataFrame-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ setValidity2("DataFrame", .valid.DataFrame)
###

### Low-level constructor. For internal use only.
### Note that, when supplied, 'nrows' is trusted.
### Calling 'new_DataFrame(x)' on an ordinary named list 'x' will turn it
### into a DataFrame in the most possibly straightforward way, that is,
### calling 'as.list()' on the result will return a list identical to 'x'.
### Note that, when supplied, 'nrows' is trusted (except when 'listData' is a
### data.frame or data-frame-like object).
### Calling 'new_DataFrame(x)' on an ordinary named list or an ordinary
### data.frame 'x' will turn it into a DataFrame in the most possibly
### straightforward way. In particular calling 'as.list()' or 'as.data.frame()'
### on the returned DataFrame will bring back 'x'.
### This is unlike 'DataFrame(x)' or 'as(x, "DataFrame")' which can do all
### kind of hard-to-predict mangling to 'x', unless the user does something
### like 'DataFrame(lapply(x, I))'. Not super convenient or intuitive!
Expand All @@ -193,19 +195,32 @@ new_DataFrame <- function(listData=list(), nrows=NA, what="arguments")
stopifnot(isSingleNumberOrNA(nrows))
if (!is.integer(nrows))
nrows <- as.integer(nrows)
if (length(listData) == 0L) {
if (is.na(nrows))
nrows <- 0L
names(listData) <- character(0)
listData_nrow <- nrow(listData)
if (is.null(listData_nrow)) {
## 'listData' is NOT a data.frame or data-frame-like object.
if (length(listData) == 0L) {
if (is.na(nrows))
nrows <- 0L
names(listData) <- character(0)
} else {
if (is.na(nrows)) {
elt_nrows <- elementNROWS(listData)
nrows <- elt_nrows[[1L]]
if (!all(elt_nrows == nrows))
stop(wmsg(what, " imply differing number of rows"))
}
if (is.null(names(listData)))
names(listData) <- paste0("V", seq_along(listData))
}
} else {
## 'listData' is a data.frame or data-frame-like object.
if (is.na(nrows)) {
elt_nrows <- elementNROWS(listData)
nrows <- elt_nrows[[1L]]
if (!all(elt_nrows == nrows))
stop(wmsg(what, " imply differing number of rows"))
nrows <- listData_nrow
} else if (nrows != listData_nrow) {
stop(wmsg("the supplied 'nrows' does not match ",
"the nb of rows in 'listData'"))
}
if (is.null(names(listData)))
names(listData) <- paste0("V", seq_along(listData))
listData <- as.list(listData)
}
new2("DFrame", nrows=nrows, listData=listData, check=FALSE)
}
Expand Down

0 comments on commit e53a50d

Please sign in to comment.