diff --git a/DESCRIPTION b/DESCRIPTION index b6a857c2..a83abbcd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -50,7 +50,8 @@ Suggests: rmarkdown, shiny (>= 1.6), testit, - tibble + tibble, + vctrs VignetteBuilder: knitr Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index 0770b272..0ffb6936 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # DT (development version) +- `datatable()` now renders data frames with `vctrs::list_of()` list-columns (#1180, @zeehio). + # CHANGES IN DT VERSION 0.34 - DT is now released under the MIT license (previously GPL-3) (#1175). diff --git a/R/utils.R b/R/utils.R index 5b860d83..811ad371 100644 --- a/R/utils.R +++ b/R/utils.R @@ -44,6 +44,9 @@ captionString = function(caption) { boxAtomicScalarElements = function(x) { is_atomic = vapply(x, is.atomic, logical(1)) if (all(is_atomic)) { + if (inherits(x, "vctrs_list_of")) { + x <- as.list(x) + } is_scalar = lengths(x) == 1L x[is_scalar] = lapply(x[is_scalar], list) } diff --git a/tests/testit/test-utils.R b/tests/testit/test-utils.R index 46b1578f..01f79b93 100644 --- a/tests/testit/test-utils.R +++ b/tests/testit/test-utils.R @@ -5,6 +5,19 @@ assert('dropNULL() works', { (dropNULL(list(a = 1, b = NULL)) %==% list(a = 1)) }) +assert('boxAtomicScalarElements() works with vctrs::list_of lists', { + if (requireNamespace("vctrs", quietly = TRUE)) { + val1 <- list("a", c("a", "b")) + out1 <- boxAtomicScalarElements(val1) + val2 <- vctrs::as_list_of(val1) + out2 <- boxAtomicScalarElements(val2) + (out1 %==% out2) + } else { + message("test omitted: vctrs is not installed") + TRUE + } +}) + assert('upperToDash() works', { (upperToDash('fontWeight') %==% 'font-weight') (upperToDash('backgroundColor') %==% 'background-color')