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

option to not coerce dates to strings #16

Closed
jkgrain opened this issue Jan 3, 2018 · 5 comments
Closed

option to not coerce dates to strings #16

jkgrain opened this issue Jan 3, 2018 · 5 comments

Comments

@jkgrain
Copy link

jkgrain commented Jan 3, 2018

It would be really useful to be able to keep dates as dates that can be read by excel. xlsx files are not really a great way to store data, but they are a great way to feed data into excel. keeping dates as excel readable dates would make a lot of sense in a bunch of use cases.

btw for now I am using this as a workaround:

dplyr::mutate(df, date = as.numeric(date - as.Date(0, origin="1899-12-30", tz='UTC')))

where df is my dataframe and date is my column that contains dates.

@jkgrain
Copy link
Author

jkgrain commented Jan 3, 2018

of course my workaround breaks the round trip of reading the xlsx back in to R. So now my workaround is to do a vlookup in excel that converts the date to a string by wrapping the lookup value in the TEXT() function. so now my vlookup into the file generated by writexl looks like:

=VLOOKUP(TEXT(lookup_value,"yyyy-mm-dd"),lookup_range_in_writexl_sheet,column,FALSE)`

It would still be cleaner if writexl wrote a date in a format that excel recognized as a date.

@danielsjf
Copy link

Just for further reference, there is a date bug as well in Excel. They had some issues with that in readxl.

@shrektan
Copy link

shrektan commented May 7, 2018

Would anyone share me the reason that writexl chooses to coerce the Date to Character? Thanks.

writexl/R/write_xlsx.R

Lines 36 to 38 in e8d176c

for(i in which(vapply(df, inherits, logical(1), c("Date", "factor", "hms")))){
df[[i]] <- as.character(df[[i]])
}

@jeroen jeroen closed this as completed in 6d684c3 May 10, 2018
@jeroen
Copy link
Member

jeroen commented May 10, 2018

Should be fixed now!

@shrektan
Copy link

Thanks!

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

4 participants