diff --git a/DESCRIPTION b/DESCRIPTION index 60158e6..2bf4810 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,7 @@ Suggests: highr, Cairo, stringr, - testthat (>= 3.0.0), + testthat (>= 3.1.5), leaflet, withr Enhances: diff --git a/R/repr_matrix_df.r b/R/repr_matrix_df.r index fceeef9..2de047b 100644 --- a/R/repr_matrix_df.r +++ b/R/repr_matrix_df.r @@ -153,8 +153,8 @@ arr_part_format <- function(part) { arr_parts_combine <- function(parts, rownms, colnms) { omit <- attr(parts, 'omit') mat <- switch(omit, - rows = rbind(parts$upper, chars$ellip_v, parts$lower, deparse.level = 0L), - cols = cbind(parts$left, chars$ellip_h, parts$right, deparse.level = 0L), + rows = rbind(parts$upper, if (ncol(parts$upper)) chars$ellip_v, parts$lower, deparse.level = 0L), + cols = cbind(parts$left, if (nrow(parts$left)) chars$ellip_h, parts$right, deparse.level = 0L), none = parts$full, both = rbind( cbind(parts$ul, chars$ellip_h, parts$ur, deparse.level = 0L), diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 111857e..d4f21c0 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -249,3 +249,21 @@ test_that('data.table elision works in 1-column and 1-row edge cases', { DF <- data.frame(a = 1:3, b = 4:6, c = 7:9) expect_identical(repr_text(DF), repr_text(data.table::as.data.table(DF))) }) + +test_that("partially-empty matrices requiring elision can be displayed", { + withr::local_options(list( + repr.matrix.max.rows = 8L, + repr.matrix.max.cols = 8L + )) + m <- matrix(nrow = 0L, ncol = 10L) + # all on one line + expect_no_warning(expect_no_match(repr(m), "\n", fixed = TRUE)) + # always [n,] with nothing after it + expect_no_warning(expect_no_match(repr(t(m)), "\\][^\n]")) + + colnames(m) <- sprintf("A%02d", 1:10) + # gap from A04 to A07 with \cdots, then only A0n, no newline + expect_no_warning(expect_no_match(expect_match(repr(m), "A04[^A]*A07"), "\n", fixed = TRUE)) + # gap from A04 to A07 with \vdots, all A0n followed by newline + expect_no_warning(expect_no_match(expect_match(repr(t(m)), "A04[^A]*A07"), "A0[1-9][^\n]")) +})