From 89bdee033dc54c9edc838d6af0283fece40baa08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 4 Dec 2022 20:44:40 +0100 Subject: [PATCH] Avoid warning with S4 character classes --- DESCRIPTION | 1 + R/shaft-.R | 5 +++++ tests/testthat/_snaps/shaft-.md | 9 +++++++++ tests/testthat/test-shaft-.R | 6 ++++++ 4 files changed, 21 insertions(+) create mode 100644 tests/testthat/_snaps/shaft-.md create mode 100644 tests/testthat/test-shaft-.R diff --git a/DESCRIPTION b/DESCRIPTION index 4fcaa17fe..822d85129 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,6 +29,7 @@ Imports: vctrs (>= 0.5.0) Suggests: bit64, + DBI, debugme, DiagrammeR, dplyr, diff --git a/R/shaft-.R b/R/shaft-.R index c17d37915..4fa8e8046 100644 --- a/R/shaft-.R +++ b/R/shaft-.R @@ -313,6 +313,11 @@ pillar_shaft.character <- function(x, ..., min_width = NULL) { min_chars <- get_pillar_option_min_chars() } + if (isS4(out)) { + # Remove S4 bit: + out <- unclass(out)[seq_along(out)] + } + pillar_shaft(as_glue(out), ..., min_width = min_chars, na_indent = na_indent, shorten = pillar_attr$shorten) } diff --git a/tests/testthat/_snaps/shaft-.md b/tests/testthat/_snaps/shaft-.md new file mode 100644 index 000000000..8f6151a05 --- /dev/null +++ b/tests/testthat/_snaps/shaft-.md @@ -0,0 +1,9 @@ +# S4 character class (tidyverse/tibble#1367) + + Code + pillar(DBI::SQL("x")) + Output + + + x + diff --git a/tests/testthat/test-shaft-.R b/tests/testthat/test-shaft-.R new file mode 100644 index 000000000..a70f1a952 --- /dev/null +++ b/tests/testthat/test-shaft-.R @@ -0,0 +1,6 @@ +test_that("S4 character class (tidyverse/tibble#1367)", { + skip_if_not_installed("DBI") + expect_snapshot({ + pillar(DBI::SQL("x")) + }) +})