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
This essentially a duplicate of tidyverse/vroom#422, but I wanted to show that the same issue exists in readr.edition 1 as well. Overall - fractional seconds that are in a col_time column need to be handled by the user with care but if it is a col_datetime it's likely fine.
This is the option needed to set to see fractional seconds when printing
options(digits.secs=3)
options(readr.edition=1L)
Load hms so we can see things as times versus difftime objects
library(hms)
Example File
url="https://github.com/r-lib/vroom/files/8353807/62163.csv.gz"file= file.path(tempdir(), basename(url))
if (!file.exists(file)) {
curl::curl_download(url, file)
}
Data Header
We see the fractional seconds in this file, which is needed for our analysis.
The default %AT I don’t think takes into account fractional seconds, so
we need to pass our own format in:
Here we specify the col_time so that it uses %OS, which I think is
R-specific as per ?strptime
Overall, that may be the end of it to be an issue to point to people in
the future. I’m not sure if there should be warning that things
may be truncated or whether this should/could guess fractional seconds.
Below I just show that the default for a datetime does preserve fractional
seconds and the format of how you store dates and times can lead to
fractional second differences.
Datetime versus time object
If we have a file with a datetime, then this doesn’t seem to be an issue:
Example File
url="https://github.com/r-lib/vroom/files/8353874/62163_data.csv.gz"file= file.path(tempdir(), basename(url))
if (!file.exists(file)) {
curl::curl_download(url, file)
}
Data Header
We see the fractional seconds in this file, which is needed for our analysis.
This essentially a duplicate of tidyverse/vroom#422, but I wanted to show that the same issue exists in
readr.edition
1 as well. Overall - fractional seconds that are in acol_time
column need to be handled by the user with care but if it is acol_datetime
it's likely fine.This is the option needed to set to see fractional seconds when printing
Load
hms
so we can see things as times versusdifftime
objectslibrary(hms)
Example File
Data Header
We see the fractional seconds in this file, which is needed for our analysis.
Reading data with
vroom
Here we read the data and see that the output is a
col_time
objectNo fractional seconds are printed:
We can confirm that they are truncated.
Different
col_time
formatThe default
%AT
I don’t think takes into account fractional seconds, sowe need to pass our own format in:
Here we specify the
col_time
so that it uses%OS
, which I think isR-specific as per
?strptime
read in the data
Fractional seconds are preserved
Overall, that may be the end of it to be an issue to point to people in
the future. I’m not sure if there should be warning that things
may be truncated or whether this should/could guess fractional seconds.
Below I just show that the default for a
datetime
does preserve fractionalseconds and the format of how you store dates and times can lead to
fractional second differences.
Datetime versus time object
If we have a file with a datetime, then this doesn’t seem to be an issue:
Example File
Data Header
We see the fractional seconds in this file, which is needed for our analysis.
Reading data with
vroom
Here we read the data and see that the output is a
col_time
objectWe see fractional seconds are preserved:
We can confirm that they are preserved
Separated Date and Time
If we have a file with 2 columns, separated in date and time, where
time, has fractional seconds, then this is again an issue as the
original issue.
Example File
Data Header
We see the fractional seconds in this file.
Reading data with
vroom
Here we read the data and see that the output is a
col_time
objectNo fractional seconds are printed:
We can confirm that they are truncated.
Created on 2022-03-25 by the reprex package (v2.0.1)
Session info
The text was updated successfully, but these errors were encountered: