kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

Errors with single row tables using latex_options = "striped" and col.names = NULL

Open PKunze-sDiv opened this issue 3 years ago • 0 comments

Hi,

I'm using kableExtra in R Markdown to create tables in PDFs. It seems as if kableExtra is having issues with single row tibbles / data frames. (Yes, one row only is a rare case. I'm displaying survey results where discarding all NA responses can result in one answer only.)

Using kbl(col.names = NULL, format = "latex") gives me the following two errors: a) The latex option "striped" results in "Error in seq.default(1, table_info$nrow - table_info$position_offset, : wrong sign in 'by' argument" My guess is that kableExtra is expecting as least two rows in order to color the second one but can't find it. I'm not sure whether this error is related to issue #571

b) Setting a column width with column_spec results in "Error in if (bold) { : missing value where TRUE/FALSE is required"

Both errors only occur with tibbles or data frames of one row only. Setting booktabs = TRUE or omitting col.names = NULL will prevent the errors.

The following code reproduces the error:

library(tibble)
library(kableExtra)
a <- tibble(b = "Hello World", c = "Goodbye")
a %>%
kbl(col.names = NULL, format    = "latex") %>%
# uncomment this to produce error a)
#kable_styling(latex_options = c("striped"), position = "left") %>%
# uncomment this to produce error b)
#column_spec(1, width = "16cm") %>%
print

Best, Peter

PKunze-sDiv avatar Apr 29 '21 12:04 PKunze-sDiv