Skip to content

Commit

Permalink
Avoid warning with S4 character classes
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Dec 4, 2022
1 parent 7e55d9b commit 89bdee0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Imports:
vctrs (>= 0.5.0)
Suggests:
bit64,
DBI,
debugme,
DiagrammeR,
dplyr,
Expand Down
5 changes: 5 additions & 0 deletions R/shaft-.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/shaft-.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# S4 character class (tidyverse/tibble#1367)

Code
pillar(DBI::SQL("x"))
Output
<pillar>
<SQL>
x

6 changes: 6 additions & 0 deletions tests/testthat/test-shaft-.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("S4 character class (tidyverse/tibble#1367)", {
skip_if_not_installed("DBI")
expect_snapshot({
pillar(DBI::SQL("x"))
})
})

0 comments on commit 89bdee0

Please sign in to comment.