diff --git a/DESCRIPTION b/DESCRIPTION index 2fa3159..77700cb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Imports: grDevices, htmltools, jsonlite, - pillar, + pillar (>= 1.4.0), base64enc Suggests: methods, @@ -30,7 +30,7 @@ Suggests: Cairo, stringr, testthat, - diffobj, + diffobj (>= 0.2.3), leaflet Enhances: data.table, diff --git a/R/repr_matrix_df.r b/R/repr_matrix_df.r index c2b9944..d134491 100644 --- a/R/repr_matrix_df.r +++ b/R/repr_matrix_df.r @@ -150,10 +150,10 @@ repr_matrix_generic <- function( is_matrix <- !is.list(x) cls <- if (!is.null(caption_override)) caption_override - else if (!is.object(x)) class(x)[[1]] - else type_sum(x) + else if (class(x)[[1]] == 'tbl_df') 'tibble' + else class(x)[[1]] dims <- dim(x) - types <- if (is_matrix) type_sum(x) else { + types <- if (is_matrix) type_sum(as.vector(x)) else { type_vec <- sprintf('<%s>', sapply(x, type_sum)) # A row limit of 3 is the minimal choice, but we only have 1 anyway as.vector(ellip_limit_arr(matrix(type_vec, nrow = 1L), 3L, cols)) diff --git a/tests/testthat/helpers.r b/tests/testthat/helpers.r index e0efeb7..bb9a678 100644 --- a/tests/testthat/helpers.r +++ b/tests/testthat/helpers.r @@ -8,12 +8,10 @@ expect_id_text <- function(object, expected) { object <- strsplit(object, '\n')[[1]] expected <- strsplit(expected, '\n')[[1]] } - if (!identical(object, expected)) { - dif <- diffobj::diffChr(object, expected, format = 'ansi256', ignore.white.space = FALSE, interactive = FALSE) - fail_msg <- as.character(dif) - if (!one_element) fail_msg <- paste(format(seq_along(fail_msg)), fail_msg) - expect(!any(dif), fail_msg) - } + dif <- diffobj::diffChr(object, expected, format = 'ansi256', ignore.white.space = FALSE, interactive = FALSE) + fail_msg <- as.character(dif) + if (!one_element) fail_msg <- paste(format(seq_along(fail_msg)), fail_msg) + expect(!any(dif), fail_msg) } expect_equivalent_string <- function(result, expectation){ diff --git a/tests/testthat/test_repr_array_df.r b/tests/testthat/test_repr_array_df.r index bd203e1..914f0d7 100644 --- a/tests/testthat/test_repr_array_df.r +++ b/tests/testthat/test_repr_array_df.r @@ -112,7 +112,7 @@ test_that('matrices in data.frames work', { expect_id_text(repr_markdown(df), ' A data.frame: 3 \u00D7 5 -| Species <fct> | Sepal.Length <dbl> | Sepal.Width <dbl> | Petal.Length <dbl> | Petal.Width <dbl> | +| Species <fct> | Sepal.Length <dbl[,2]> | Sepal.Width <dbl[,2]> | Petal.Length <dbl[,2]> | Petal.Width <dbl[,2]> | |---|---|---|---|---| | setosa | 4.3, 5.8 | 2.3, 4.4 | 1.0, 1.9 | 0.1, 0.6 | | versicolor | 4.9, 7.0 | 2.0, 3.4 | 3.0, 5.1 | 1.0, 1.8 |