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

Fail to preserve Date object #13

Closed
renkun-ken opened this issue Jan 9, 2015 · 5 comments
Closed

Fail to preserve Date object #13

renkun-ken opened this issue Jan 9, 2015 · 5 comments
Labels

Comments

@renkun-ken
Copy link

If a column of a data frame is Date or POSIXct or POSIXlt-class vector, they will be printed as integers in the column.

library(DT)
datatable(data.frame(date = seq(as.Date("2015-01-01"), by = "day", length.out = 5), x = 1:5))

will produce a DataTable like

date    x
16436   1
16437   2
16438   3
16439   4
16440   5

The same thing does not happen with knitr::kable:

> knitr::kable(data.frame(date = seq(as.Date("2015-01-01"), by = "day", length.out = 5), x = 1:5))


|date       |  x|
|:----------|--:|
|2015-01-01 |  1|
|2015-01-02 |  2|
|2015-01-03 |  3|
|2015-01-04 |  4|
|2015-01-05 |  5|
@yihui
Copy link
Member

yihui commented Jan 12, 2015

That is a problem of RJSONIO. Sigh. It seems every single problem of RJSONIO has been well solved in jsonlite, but we are just stuck in RJSONIO:

> x = data.frame(date = seq(as.Date("2015-01-01"), by = "day", length.out = 5), x = 1:5)
> RJSONIO::toJSON(x)
[1] "{\n \"date\": [ 16436, 16437, 16438, 16439, 16440 ],\n\"x\": [ 1, 2, 3, 4, 5 ] \n}"
> jsonlite::toJSON(x)
[{"date":"2015-01-01","x":1},{"date":"2015-01-02","x":2},{"date":"2015-01-03","x":3},{"date":"2015-01-04","x":4},{"date":"2015-01-05","x":5}] 

@juancentro
Copy link

@yihui are you in the middle of solving this? I just installed the latest DT and when a DT has date columns it doesn't print anything
datatable(data.frame(x = Sys.Date()))

@jcheng5
Copy link
Member

jcheng5 commented Jan 30, 2015

duncantl/RJSONIO#3

:(

@yihui yihui added the bug label Feb 11, 2015
@yihui yihui closed this as completed in e6ee2fa Feb 11, 2015
yihui added a commit that referenced this issue Feb 11, 2015
@yihui
Copy link
Member

yihui commented Feb 11, 2015

Should be "fixed" now. Thanks!

@renkun-ken
Copy link
Author

Appreciate your work! Will try it out.

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

No branches or pull requests

4 participants