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

knitr:: kable changes chron dates #1118

Closed
liesb opened this issue Oct 18, 2015 · 4 comments
Closed

knitr:: kable changes chron dates #1118

liesb opened this issue Oct 18, 2015 · 4 comments
Labels
bug Bugs
Milestone

Comments

@liesb
Copy link

liesb commented Oct 18, 2015

Not sure whether this is related to #806.
Dates (and differences, ie time between, between dates) in dataframes change once they are printed using kable.

Reproducible ( I hope :) ) example:

x <- chron(dates = c("02/27/92", "02/27/92", "01/14/92", "02/28/92"))
y <- x + c(1,2,3,4)
df <- data.frame(x=x, y=y)
df$diff <- y - x
df
knitr::kable(df)

will give

df
x y diff
1 02/27/92 02/28/92 1
2 02/27/92 02/29/92 2
3 01/14/92 01/17/92 3
4 02/28/92 03/03/92 4

kable(df)

x y diff
02/27/92 02/27/92 0
02/27/92 02/27/92 0
01/16/92 01/16/92 0
02/27/92 03/05/92 7
@aniruhil
Copy link

What about using

df$diff = difftime(y, x, units = "days")

df
x y diff
1 02/27/92 02/28/92 1 days
2 02/27/92 02/29/92 2 days
3 01/14/92 01/17/92 3 days
4 02/28/92 03/03/92 4 days

knitr::kable(df)

knitr::kable(df)

x y diff
02/27/92 02/27/92 1 days
02/27/92 02/27/92 2 days
01/16/92 01/16/92 3 days
02/27/92 03/05/92 4 days

@liesb
Copy link
Author

liesb commented Oct 18, 2015

Thank you! I don't really need the workaround at the moment, but I thought I'd report the original issue.

@yihui yihui added this to the v1.12 milestone Oct 28, 2015
@yihui yihui added the bug Bugs label Oct 28, 2015
@yihui yihui closed this as completed in a69f4f5 Oct 28, 2015
@yihui
Copy link
Owner

yihui commented Oct 28, 2015

Yes, that is a similar issue as #806. I just fixed it. Thanks!

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

3 participants