knitr
knitr copied to clipboard
FR: add the option of naming the column of row.names
I would like to explicit a name for the column of row.names
so I try
d2 = head(mtcars)
kable(d2[, 1:5], col.names = c("car", names(d2[, 1:5])))
Error in dimnames(x) <- dn :
length of 'dimnames' [2] not equal to array extent
Maybe, another option would be allow a string for row.names
as follows -kable(d2[, 1:5], row.names = "cars")
-, so kable
would understand it as a TRUE
and further naming the column.
Thank you!
By filing an issue to this repo, I promise that
- [x] I have fully read the issue guide at https://yihui.org/issue/.
- [x] I have provided the necessary information about my issue.
- If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
- If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
. - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [x] I have learned the Github Markdown syntax, and formatted my issue correctly.
I understand that my issue may be closed if I don't fulfill my promises.
I have experienced the same situation and worked around with tibble::rownames_to_column
.
d2 = head(mtcars)
d2[1:5] |>
tibble::rownames_to_column() |>
kable(col.names = c("car", names(d2[1:5]))
allow a string for row.names
This may be confusing because users would analogize the similar behavior among col.names
and row.names
.
As documented, kable
is a very simple table generator.
I think complex steps should come prior to kable
when possible.
Should be fixed now. Thanks for the report!
Thank you! @yihui
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.