Skip to content

Commit

Permalink
don't repeat NULL in dimnames obj
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Nov 11, 2017
1 parent 18b8bf8 commit 36ca67b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 4 additions & 1 deletion R/bind.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ bind = function(arrayList, along=length(dim(arrayList[[1]]))+1) {
arrayList = vectors_to_row_or_col(arrayList, along=along)
re = do.call(function(...) abind::abind(..., along=along), arrayList)

# is.null(...) required because R is stupid
if (dim(re)[along] == length(arrayList) && !is.null(names(arrayList)))
dimnames(re)[[along]] = names(arrayList)

# replace list of NULLs to one NULL to be consistent with base R
if (all(sapply(dimnames(re), is.null)))
dimnames(re) = NULL

re
}
8 changes: 3 additions & 5 deletions tests/testthat/test-bind.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("bind")

test_that("vector", {
ref = cbind(1:2, 3:4)
ref = rbind(1:2, 3:4)
expect_equal(ref, bind(list(1:2, 3:4), along=1))
expect_equal(ref, t(bind(list(1:2, 3:4), along=2)))
})
Expand All @@ -13,9 +13,7 @@ test_that("keep names", {
expect_equal(names(x), rownames(m))

colnames(m) = LETTERS[1:2]
expect_equal(bind(list(m,m), along=1),
rbind(m, m))
expect_equal(bind(list(m,m), along=1), rbind(m, m))

expect_equal(bind(list(m,m), along=2),
cbind(m, m))
expect_equal(bind(list(m,m), along=2), cbind(m, m))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-mask.r
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ test_that("mask", {
2L), .Dimnames = list(c("a", "b", "c"), c("e1", "e2")))

expect_equal(Zref, Z)
expect_equal(Zref, mask(Z, along=2))
expect_equal(Zref, t(mask(Z, along=1)))
expect_equal(Zref, mask(F, along=2))
expect_equal(Zref, t(mask(F, along=1)))
})

0 comments on commit 36ca67b

Please sign in to comment.