Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readr::read_csv excludes milliseconds from timestamps #1095

Closed
bastianilso opened this issue May 15, 2020 · 3 comments
Closed

readr::read_csv excludes milliseconds from timestamps #1095

bastianilso opened this issue May 15, 2020 · 3 comments

Comments

@bastianilso
Copy link

(see original issue at tidyverse/purrr#764)

reading the following csv file with readr::read_csv removes milliseconds in timestamps (formatted HH:mm:ss.ffff). Reading with base read.csv works fine.

with the following file
sampleLog_2020-05-13 10-30-10.0167.zip

try:

  df2<-readr::read_csv("sampleLog_2020-05-13 10-30-10.0167.csv")

image

compare to

  df2<-read.csv("sampleLog_2020-05-13 10-30-10.0167.csv")

image

@jimhester
Copy link
Collaborator

This is a duplicate of #883

readr is actually reading the seconds, but R does not display fractional seconds by default.

library(readr)
data <- read_csv("~/p/readr/sampleLog_2020-05-13 10-30-10.0167.csv")
#> Parsed with column specification:
#> cols(
#>   .default = col_double(),
#>   TimeStamp = col_datetime(format = ""),
#>   Time = col_time(format = ""),
#>   Date = col_date(format = ""),
#>   Event = col_character(),
#>   PupilTime = col_character(),
#>   UnityToPupilTimeOffset = col_character(),
#>   GazeConfidence = col_character(),
#>   EyeCenter0X = col_character(),
#>   EyeCenter0Y = col_character(),
#>   EyeCenter0Z = col_character(),
#>   EyeCenter1X = col_character(),
#>   EyeCenter1Y = col_character(),
#>   EyeCenter1Z = col_character(),
#>   GazeNormal0X = col_character(),
#>   GazeNormal0Y = col_character(),
#>   GazeNormal0Z = col_character(),
#>   GazeNormal1X = col_character(),
#>   GazeNormal1Y = col_character(),
#>   GazeNormal1Z = col_character(),
#>   LocalGazeDirectionX = col_character()
#>   # ... with 17 more columns
#> )
#> See spec(...) for full column specifications.

as.POSIXlt(data$TimeStamp[[1]])$sec
#> [1] 10.0177

Created on 2020-06-05 by the reprex package (v0.3.0)

@bastianilso
Copy link
Author

@jimhester I tried your command below and it works for the column Timestamp. But when I try to do it on the column Time, I again only get the result in seconds.

image

@kalenkovich
Copy link

The issue is still present 2.1.4.

@jimhester, I don't think this is the display issue: OP's problem (and mine) is with the Time column, not TimeStamp. readr correctly guesses that the Time column contains time values and parses it as "hms" but the milliseconds are silently dropped.

library(readr)

filename <- "sampleLog_2020-05-13 10-30-10.0167.csv"
test <- read_csv(filename)
print(as.double(test$Time[[1]]), digits = 20)
# 37810

test2 <- read_csv(filename, col_types = cols(Time = col_character))
> print(as.double(as_hms(test2$Time[[1]])), digits = 20)
[1] 37810.017699956893921

Maybe there is a format specification for col_time that would work here? But in any case, it would be useful if readr at least produced a warning about the loss of precision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants