From 33d475b5e7545ac333401b172be72f27f4e24016 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 28 Apr 2025 13:24:50 -0700 Subject: [PATCH 01/10] Don't include '...' to empty-dimensional matrices --- R/repr_matrix_df.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/repr_matrix_df.r b/R/repr_matrix_df.r index af8dcbe..2408526 100644 --- a/R/repr_matrix_df.r +++ b/R/repr_matrix_df.r @@ -116,8 +116,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 (nrow(parts$upper)) chars$ellip_v, parts$lower, deparse.level = 0L), + cols = cbind(parts$left, if (ncol(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), From 91296fdfd14bde7b5447f40f1ce2453832921daf Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 28 Apr 2025 13:37:23 -0700 Subject: [PATCH 02/10] regression tests --- tests/testthat/test_repr_array_df.r | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 816e8b0..84a3d0d 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -204,3 +204,17 @@ test_that('data.frame with list columns can be displayed', { expect_identical(repr_html(data.table::as.data.table(df)), sub('data\\.frame','data.table',expected)) } }) + +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) + expect_silent(repr(m)) + expect_silent(repr(t(m)) + + colnames(m) <- sprintf("A%02d", 1:10) + expect_match(repr(m), "A04[^A]*A07") + expect_match(repr(t(m)), "A04[^A]*A07") +}) From 434ee9c113e3029d78f479299266c3b0475fd950 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 28 Apr 2025 13:38:00 -0700 Subject: [PATCH 03/10] flip which dimension is tested --- R/repr_matrix_df.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/repr_matrix_df.r b/R/repr_matrix_df.r index 2408526..f4b0030 100644 --- a/R/repr_matrix_df.r +++ b/R/repr_matrix_df.r @@ -116,8 +116,8 @@ arr_part_format <- function(part) { arr_parts_combine <- function(parts, rownms, colnms) { omit <- attr(parts, 'omit') mat <- switch(omit, - rows = rbind(parts$upper, if (nrow(parts$upper)) chars$ellip_v, parts$lower, deparse.level = 0L), - cols = cbind(parts$left, if (ncol(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), From de92d1812f0c99436743baa0f74be7bc7d35418e Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 23 Jul 2025 09:19:52 -0700 Subject: [PATCH 04/10] msising ')' --- tests/testthat/test_repr_array_df.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 4c7dba9..abe9b56 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -257,7 +257,7 @@ test_that("partially-empty matrices requiring elision can be displayed", { )) m <- matrix(nrow = 0L, ncol = 10L) expect_silent(repr(m)) - expect_silent(repr(t(m)) + expect_silent(repr(t(m))) colnames(m) <- sprintf("A%02d", 1:10) expect_match(repr(m), "A04[^A]*A07") From 98c56fdb80fc47f274f6401962fe0a1016e45182 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 25 Jul 2025 09:46:42 -0700 Subject: [PATCH 05/10] stronger test --- tests/testthat/test_repr_array_df.r | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index abe9b56..e43ffca 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -260,6 +260,7 @@ test_that("partially-empty matrices requiring elision can be displayed", { expect_silent(repr(t(m))) colnames(m) <- sprintf("A%02d", 1:10) - expect_match(repr(m), "A04[^A]*A07") + # gap from A04 to A07 with \cdots, then only A0n, no newline + expect_silent(expect_match(repr(m), "A04[^A]*A07[A0-9 ]*$")) expect_match(repr(t(m)), "A04[^A]*A07") }) From 5c2cd189e44f14e6bace01b18bc970e8fa5a1667 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 25 Jul 2025 09:48:24 -0700 Subject: [PATCH 06/10] similar test in the no-colnames case --- tests/testthat/test_repr_array_df.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index e43ffca..37087bc 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -256,7 +256,7 @@ test_that("partially-empty matrices requiring elision can be displayed", { repr.matrix.max.cols = 8L )) m <- matrix(nrow = 0L, ncol = 10L) - expect_silent(repr(m)) + expect_silent(expect_match(repr(m), "^[^\n]*$")) expect_silent(repr(t(m))) colnames(m) <- sprintf("A%02d", 1:10) From 742f08d2dc5e1b5e295d23921c14345da3595eac Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 25 Jul 2025 09:51:02 -0700 Subject: [PATCH 07/10] use expect_no* matchers --- tests/testthat/test_repr_array_df.r | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 37087bc..64ec7ef 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -256,11 +256,11 @@ test_that("partially-empty matrices requiring elision can be displayed", { repr.matrix.max.cols = 8L )) m <- matrix(nrow = 0L, ncol = 10L) - expect_silent(expect_match(repr(m), "^[^\n]*$")) - expect_silent(repr(t(m))) + expect_no_warning(expect_no_match(repr(m), "\n", fixed = TRUE)) + expect_no_warning(repr(t(m))) colnames(m) <- sprintf("A%02d", 1:10) # gap from A04 to A07 with \cdots, then only A0n, no newline - expect_silent(expect_match(repr(m), "A04[^A]*A07[A0-9 ]*$")) - expect_match(repr(t(m)), "A04[^A]*A07") + expect_no_warning(expect_match(repr(m), "A04[^A]*A07[A0-9 ]*$")) + expect_no_warning(expect_match(repr(t(m)), "A04[^A]*A07")) }) From af289cdd8a191254ab5e635ca087a9405083a9f8 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 25 Jul 2025 09:51:59 -0700 Subject: [PATCH 08/10] requires more recent testthat (2022) --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 98d1ddabcc0d657cfbf3d5ebfd97941cc71d4209 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 25 Jul 2025 10:00:44 -0700 Subject: [PATCH 09/10] simplify regexes by using expect_match()+expect_no_match() --- tests/testthat/test_repr_array_df.r | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 64ec7ef..4a56bfa 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -256,11 +256,13 @@ test_that("partially-empty matrices requiring elision can be displayed", { 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)) - expect_no_warning(repr(t(m))) + # 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_match(repr(m), "A04[^A]*A07[A0-9 ]*$")) - expect_no_warning(expect_match(repr(t(m)), "A04[^A]*A07")) + expect_no_warning(expect_no_match(expect_match(repr(m), "A04[^A]*A07"), "\n", fixed = TRUE)) + expect_no_warning(expect_no_match(expect_match(repr(t(m)), "A04[^A]*A07"), "A0[1-9][^\n]")) }) From a2b196c9bbcb1b38f7998b02ab30e8f7ae5542c7 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 25 Jul 2025 10:01:35 -0700 Subject: [PATCH 10/10] symmetric comment --- tests/testthat/test_repr_array_df.r | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 4a56bfa..d4f21c0 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -264,5 +264,6 @@ test_that("partially-empty matrices requiring elision can be displayed", { 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]")) })