[Rd] Printing digits.secs on data.frame?
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Thu Jul 18 18:51:47 CEST 2024
On 18 July 2024 at 12:14, John Muschelli wrote:
| Is there a way to have printing data.frames with POSIXct to display
| milliseconds if digits.secs is set as a default?
I suspect this would require a change to the corresonding print method.
| You can use the digits argument in print, such as print(df, digits = 3) to
| get the intended output, but I assumed it was done with the option
| digits.secs set. Tibbles by default do this printing, which is shown
| below, but I was unsure if digits.secs should affect printing data.frames,
| as we see below it affects printing POSIXct outside of a data.frame.
|
| ``` r
| df = structure(list(time = structure(c(1509375600, 1509375600.03333,
| 1509375600.06667, 1509375600.1,
| 1509375600.13333, 1509375600.16667
| ), class = c("POSIXct", "POSIXt"), tzone = "GMT"),
| X = c(0.188,
| 0.18, 0.184, 0.184, 0.184, 0.184),
| Y = c(0.145, 0.125, 0.121,
| 0.121, 0.117, 0.125),
| Z = c(-0.984, -0.988, -0.984, -0.992, -0.988,
| -0.988)), row.names = c(NA, 6L), class = "data.frame")
I like data.table as a (well-behaved) generalisation of data.frame and use it
in cases like this (and others). It does what you desire (and I also default
to digits.secs=6 in my startup code, and may have another data.table
formating option enabled)
> data.table::data.table(df)
time X Y Z
<POSc> <num> <num> <num>
1: 2017-10-30 15:00:00.00000 0.188 0.145 -0.984
2: 2017-10-30 15:00:00.03332 0.180 0.125 -0.988
3: 2017-10-30 15:00:00.06666 0.184 0.121 -0.984
4: 2017-10-30 15:00:00.09999 0.184 0.121 -0.992
5: 2017-10-30 15:00:00.13333 0.184 0.117 -0.988
6: 2017-10-30 15:00:00.16667 0.184 0.125 -0.988
>
But I concur that it would be nice to potentially have this for data.frame
too. Given the amount of code out there that might be affected a change may
have to be conditional on another option.
Dirk
--
dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org
More information about the R-devel
mailing list