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

read_xls rounding date times when col_types="text" #430

Closed
KyleHaynes opened this Issue Mar 15, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@KyleHaynes

KyleHaynes commented Mar 15, 2018

Hello,
Curious to know why read_xlsx and readl_xls treat date times differently when coercing them to text?

Is this a bug? or expected behaviour?

Code below
test.xlsx
test.xls

# Create a date time tibble
date_time_tibble <- structure(list(a = structure(c(479394000, 479395412), class = c("POSIXct", 
"POSIXt"), tzone = "UTC")), .Names = "a", row.names = c(NA, -2L
), class = c("tbl_df", "tbl", "data.frame"))

# Write it out
writexl::write_xlsx(date_time_tibble,"test.xlsx")

# Manually save test.xlsx to a xls formatted file using MS Excel
readxl::read_xlsx("test.xlsx",col_types="guess")
# A tibble: 2 x 1
  a                  
  <dttm>             
1 1985-03-11 13:00:00
2 1985-03-11 13:23:32
# - Looks fine.

readxl::read_xls("test.xls",col_types="guess")
# A tibble: 2 x 1
  a                  
  <dttm>             
1 1985-03-11 13:00:00
2 1985-03-11 13:23:32
# - Looks fine.

readxl::read_xlsx("test.xlsx",col_types="text")
# A tibble: 2 x 1
  a                
  <chr>            
1 31117.54166666667
2 31117.55800925926
# - Looks fine, no rounding

readxl::read_xls("test.xls",col_types="text")
# A tibble: 2 x 1
  a      
  <chr>  
1 31117.5
2 31117.6
# - Why does it round?
@jennybc

This comment has been minimized.

Member

jennybc commented Mar 16, 2018

This rings no bells, so I am guessing NO not intentional or expected.

@jennybc jennybc closed this in #431 Mar 16, 2018

jennybc added a commit that referenced this issue Mar 16, 2018

Increase precision of xls datetimes when coerced to character (#431)
* Add failing test

* Increase precision of xls datetimes when coerced to text

Fixes #430

* Print with full precision

As per @jimhester's advice:

https://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout#comment29144568_554134

* Make test a bit more forgiving

* Add NEWS bullet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment