Skip to content

Commit 826281b

Browse files
Don't include '...' to empty-dimensional matrices (#174)
* Don't include '...' to empty-dimensional matrices * regression tests * flip which dimension is tested * msising ')' * stronger test * similar test in the no-colnames case * use expect_no* matchers * requires more recent testthat (2022) * simplify regexes by using expect_match()+expect_no_match() * symmetric comment
1 parent ffd977c commit 826281b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Suggests:
3131
highr,
3232
Cairo,
3333
stringr,
34-
testthat (>= 3.0.0),
34+
testthat (>= 3.1.5),
3535
leaflet,
3636
withr
3737
Enhances:

R/repr_matrix_df.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ arr_part_format <- function(part) {
153153
arr_parts_combine <- function(parts, rownms, colnms) {
154154
omit <- attr(parts, 'omit')
155155
mat <- switch(omit,
156-
rows = rbind(parts$upper, chars$ellip_v, parts$lower, deparse.level = 0L),
157-
cols = cbind(parts$left, chars$ellip_h, parts$right, deparse.level = 0L),
156+
rows = rbind(parts$upper, if (ncol(parts$upper)) chars$ellip_v, parts$lower, deparse.level = 0L),
157+
cols = cbind(parts$left, if (nrow(parts$left)) chars$ellip_h, parts$right, deparse.level = 0L),
158158
none = parts$full,
159159
both = rbind(
160160
cbind(parts$ul, chars$ellip_h, parts$ur, deparse.level = 0L),

tests/testthat/test_repr_array_df.r

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,21 @@ test_that('data.table elision works in 1-column and 1-row edge cases', {
249249
DF <- data.frame(a = 1:3, b = 4:6, c = 7:9)
250250
expect_identical(repr_text(DF), repr_text(data.table::as.data.table(DF)))
251251
})
252+
253+
test_that("partially-empty matrices requiring elision can be displayed", {
254+
withr::local_options(list(
255+
repr.matrix.max.rows = 8L,
256+
repr.matrix.max.cols = 8L
257+
))
258+
m <- matrix(nrow = 0L, ncol = 10L)
259+
# all on one line
260+
expect_no_warning(expect_no_match(repr(m), "\n", fixed = TRUE))
261+
# always [n,] with nothing after it
262+
expect_no_warning(expect_no_match(repr(t(m)), "\\][^\n]"))
263+
264+
colnames(m) <- sprintf("A%02d", 1:10)
265+
# gap from A04 to A07 with \cdots, then only A0n, no newline
266+
expect_no_warning(expect_no_match(expect_match(repr(m), "A04[^A]*A07"), "\n", fixed = TRUE))
267+
# gap from A04 to A07 with \vdots, all A0n followed by newline
268+
expect_no_warning(expect_no_match(expect_match(repr(t(m)), "A04[^A]*A07"), "A0[1-9][^\n]"))
269+
})

0 commit comments

Comments
 (0)