Skip to content

Commit

Permalink
fix formatting of numeric-like objects with length != 1, closes #88
Browse files Browse the repository at this point in the history
- Fix error when formatting numeric values with a `"class"` attribute with length != 1 (#88).
  • Loading branch information
krlmlr committed Feb 26, 2018
1 parent a2d528c commit 8472829
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Imports:
utf8 (>= 1.1.3)
Suggests:
knitr (>= 1.19),
lubridate,
testthat (>= 2.0.0)
Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd", "pkgapi::api_roclet"))
RoxygenNote: 6.0.1.9000
Expand Down
2 changes: 1 addition & 1 deletion R/shaft.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pillar_shaft.logical <- function(x, ...) {
pillar_shaft.numeric <- function(x, ..., sigfig = getOption("pillar.sigfig", 3)) {
if (!is.null(attr(x, "class"))) {
ret <- format(x)
return(new_pillar_shaft_simple(ret, width = get_extent(ret), align = "left"))
return(new_pillar_shaft_simple(ret, width = get_max_extent(ret), align = "left"))
}

dec <- format_decimal(x, ..., sigfig = sigfig)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/out/lubridate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<S4: Duration>
1s
2s
3s
7 changes: 7 additions & 0 deletions tests/testthat/test-format_lubridate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
context("format_lubridate")

test_that("can output durations", {
v <- lubridate::as.duration(1:3)
x <- pillar(v)
expect_pillar_output(xp = v, filename = "lubridate.txt")
})

0 comments on commit 8472829

Please sign in to comment.