df <- data_frame(dates = lubridate::ymd_hms("2016-05-21 04:59:00") + hours(0:5), my_data = 11:16)
> tz(df$dates)
[1] "UTC"
tz(df)
[1] "UTC"
> tz(df$dates) <- "America/New_York"
readr::write_csv(df, "tmp.csv")
> readr::read_csv("tmp.csv")
Source: local data frame [6 x 2]
dates my_data
(time) (int)
1 2016-05-21 08:59:00 11
2 2016-05-21 09:59:00 12
3 2016-05-21 10:59:00 13
4 2016-05-21 11:59:00 14
5 2016-05-21 12:59:00 15
> write.csv(df, "tmp.csv")
> read.csv("tmp.csv")
X dates my_data
1 1 2016-05-21 04:59:00 11
2 2 2016-05-21 05:59:00 12
3 3 2016-05-21 06:59:00 13
4 4 2016-05-21 07:59:00 14
5 5 2016-05-21 08:59:00 15
6 6 2016-05-21 09:59:00 16
--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+...@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at https://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.
Thank you for the response.
I see and agree that readr::write_csv is in fact behaving differently than base::write.csv, and that, as you point out, this difference is observable in the file output.
and yet, my question remains: is this behavior desirable and intentional, esp given that write_csv sould seems intended as a faster but side effect free/ idempotent alternative to write.csv?
as another point of comparison, the treatment of dates under
write_rds works like write.csv; ie, it coerces the actual date and
preserves it.
-- Michael Cawthon Chief Investment Officer Green Street Energy LLC mcaw...@greenstenergy.com p: 479-442-1407
from the orig post, here's a toy df:
df <- data_frame(dates = lubridate::ymd_hms("2016-05-21 04:59:00") + hours(0:5), my_data = 11:16)
dates are EST, so we set them
lubridate::tz(df$dates) <- "America/New_York"
#expected date/time behavior; note the hour
write.csv(df, "tmp.csv", row.names = FALSE)
way1 <- read_csv("tmp.csv")
way #2
#unexpected date/time behavior; note the hour shift
write_csv(df, "tmp.csv")
way2 <- read_csv("tmp.csv")
way #3
# expected date behavior
write_rds(df, "tmp.rds")
way3 <- read_rds("tmp.rds")
I'd naively expect them to all be the same
But failing that, I'd at least expect way #2 and way #3 to be consistent, but they aren't, ie:
#this is false
identical(way2, way3)