Skip to content

Commit

Permalink
fix colnames check + test
Browse files Browse the repository at this point in the history
  • Loading branch information
philouail committed Dec 5, 2024
1 parent 24e0657 commit 0d53e26
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/MsBackend.R
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ setMethod("cbind2", signature = c("MsBackend", "dataframeOrDataFrameOrmatrix"),
function(x, y = data.frame(), ...) {
if (is(y, "matrix"))
y <- as.data.frame(y)
if (any(colnames(x) %in% colnames(y)))
if (any(colnames(spectraData(x)) %in% colnames(y)))
stop("spectra variables in 'y' are already present in 'x' ",
"replacing them is not allowed")
if (nrow(y) != length(x))
Expand Down
2 changes: 1 addition & 1 deletion R/MsBackendDataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ setMethod("cbind2", signature = c("MsBackendDataFrame",
function(x, y = data.frame(), ...) {
if (is(y, "matrix"))
y <- as.data.frame(y)
if (any(colnames(x) %in% colnames(y)))
if (any(colnames(spectraData(x)) %in% colnames(y)))
stop("spectra variables in 'y' are already present in 'x' ",
"replacing them is not allowed")
if (nrow(y) != length(x))
Expand Down
2 changes: 1 addition & 1 deletion R/MsBackendMemory.R
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ setMethod("cbind2", signature = c("MsBackendMemory",
function(x, y = data.frame(), ...) {
if (is(y, "matrix"))
y <- as.data.frame(y)
if (any(colnames(x) %in% colnames(y)))
if (any(colnames(spectraData(x)) %in% colnames(y)))
stop("spectra variables in 'y' are already present in 'x' ",
"replacing them is not allowed")

Expand Down
3 changes: 3 additions & 0 deletions inst/test_backends/test_MsBackend/test_spectra_subsetting.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ test_that("cbind2 works", {
expect_true(validObject(res))
expect_equal(ncol(spectraData(res)), length(spectraVariables(be)) + 1)
expect_equal(res$m, 1:seql)
## no replacing
expect_error(cbind2(be, data.frame(scanIndex = 1:seql)),
"are already present")
})

#' extractByIndex. Uses [ if not implemented
Expand Down

0 comments on commit 0d53e26

Please sign in to comment.