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

kable(x, digits = y) fails when any column is not numeric #771

Closed
nacnudus opened this issue May 11, 2014 · 5 comments
Closed

kable(x, digits = y) fails when any column is not numeric #771

nacnudus opened this issue May 11, 2014 · 5 comments
Labels
feature Feature requests
Milestone

Comments

@nacnudus
Copy link

It would be lovely if kable could handle the rounding in this case, as it is tricky to do it manually. Perhaps "digits" could accept a vector with a value for each column, using NA for text columns.

library(knitr)
test <- data.frame(text = "hello", number1 = 1.135, number2 = 2.135)
test

##    text number1 number2
## 1 hello   1.135   2.135

kable(test, digits = 2)

## |text   |  number1|  number2|
## |:------|--------:|--------:|
## |hello  |    1.135|    2.135|

kable(test[, -1], digits = 2)

## |  number1|  number2|
## |--------:|--------:|
## |     1.14|     2.13|
@yihui yihui added this to the v1.6 milestone May 12, 2014
@yihui
Copy link
Owner

yihui commented May 12, 2014

I just tried the development version here, and the problem seems to have been fixed.

I'll think about the vector version of digits. Thanks!

@nacnudus
Copy link
Author

Thanks Yihui, sorry for not checking the dev version first.

@yihui yihui added the Feature label May 21, 2014
@yihui yihui closed this as completed in 3e01c0a May 21, 2014
@yihui
Copy link
Owner

yihui commented May 22, 2014

I have added the support for digits as a vector. Thanks!

kable(data.frame(x=rnorm(10), y=rnorm(10)), digits = c(1, 4))

@nacnudus
Copy link
Author

Awesome, thanks Yihui!

@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
feature Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants