Skip to content
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Suggests:
highr,
Cairo,
stringr,
testthat (>= 3.0.0),
testthat (>= 3.1.5),
leaflet,
withr
Enhances:
Expand Down
4 changes: 2 additions & 2 deletions R/repr_matrix_df.r
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test_repr_array_df.r
Original file line number Diff line number Diff line change
Expand Up @@ -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]"))
})