You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following discussion on #74. When the user sets digits.secs option, the fractional seconds are printed but the spacing is off because width is not adjusted dynamically. The reprex below outlines the problem and proposes a solution.
# with dev pillar and tibble
library(pillar)
library(tibble)
from<- as.POSIXct("14:03:55", format="%H:%M:%OS", tz="UTC")
to<- as.POSIXct("14:04:00", format="%H:%M:%OS", tz="UTC")
options(digits.secs=4)
ex<- tibble(datetime= seq(from, to, by=0.01))
ex$col<-100000# The correct amount of spacing is not used with fractional seconds
print(ex, n=2)
#> # A tibble: 501 x 2#> datetime col#> <dttm> <dbl>#> 1 2018-03-01 14:03:55.0000 100000.#> 2 2018-03-01 14:03:55.0099 100000.#> # ... with 499 more rows# Potential solution# This should really be pillar_shaft.POSIXt but had to do this for testing# FYI the digits.secs option allows values from 0-6 and defaults to NULL (0)pillar_shaft.POSIXct<-function (x, ...)
{
# Fractional seconds width adjustmentwidth<-19Ldigits.secs<- min(max(getOption("digits.secs"), 0L), 6L) # Clamp between 0-6if (digits.secs) {
width<-width+digits.secs+1L# The 1L is for the extra decimal point
}
date<- format(x, format="%Y-%m-%d")
time<- format(x, format="%H:%M:%OS")
datetime<- paste0(date, "", style_subtle(time))
datetime[is.na(x)] <-NA
new_pillar_shaft_simple(datetime, width=width, align="left")
}
print(ex, n=2)
#> # A tibble: 501 x 2#> datetime col#> <dttm> <dbl>#> 1 2018-03-01 14:03:55.0000 100000.#> 2 2018-03-01 14:03:55.0099 100000.#> # ... with 499 more rows# Even if the user does something crazy everything is alright...# The default
options(digits.secs=NULL)
head(ex, n=1)
#> # A tibble: 1 x 2#> datetime col#> <dttm> <dbl>#> 1 2018-03-01 14:03:55 100000.# Negative
options(digits.secs=-1)
head(ex, n=1)
#> # A tibble: 1 x 2#> datetime col#> <dttm> <dbl>#> 1 2018-03-01 14:03:55 100000.# Really big (max of 6)
options(digits.secs=12)
head(ex, n=1)
#> # A tibble: 1 x 2#> datetime col#> <dttm> <dbl>#> 1 2018-03-01 14:03:55.000000 100000.
Created on 2018-03-01 by the reprex package (v0.1.1.9000).
The text was updated successfully, but these errors were encountered:
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
Following discussion on #74. When the user sets
digits.secs
option, the fractional seconds are printed but the spacing is off becausewidth
is not adjusted dynamically. The reprex below outlines the problem and proposes a solution.Created on 2018-03-01 by the reprex package (v0.1.1.9000).
The text was updated successfully, but these errors were encountered: