diff --git a/R/repr_matrix_df.r b/R/repr_matrix_df.r index af8dcbe..f5b2730 100644 --- a/R/repr_matrix_df.r +++ b/R/repr_matrix_df.r @@ -43,8 +43,10 @@ arr_partition <- function(a, rows, cols) { # assign a list of parts that can be coerced to strings if (!is.null(part_r) && !is.null(part_c)) { structure(list( - ul = a[part_r$start, part_c$start], ll = a[part_r$end, part_c$start], - ur = a[part_r$start, part_c$end ], lr = a[part_r$end, part_c$end ]), + ul = a[part_r$start, part_c$start, drop = FALSE], + ll = a[part_r$end , part_c$start, drop = FALSE], + ur = a[part_r$start, part_c$end, drop = FALSE], + lr = a[part_r$end , part_c$end, drop = FALSE]), omit = 'both') } else if (!is.null(part_r)) { structure(list( diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index 816e8b0..2d5c726 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -204,3 +204,25 @@ 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('forced-narrow inputs work', { + withr::local_options(list(repr.matrix.max.rows = 2L, repr.matrix.max.cols = 2L)) + df <- data.frame(a = 1:3, b = 4:6, c = 7:9) + expect_silent(repr_text(df)) + expect_identical( + # Scrub non-ASCII characters to make the test platform-agnostic. + gsub("[^a-zA-Z0-9.&;<>= '\"/:\n\t]", "*", repr_html(df)), + "
| a | * | c |
|---|---|---|
| <int> | * | <int> |
| 1 | * | 7 |
| * | * | * |
| 3 | * | 9 |