kableExtra
kableExtra copied to clipboard
column_spec() fails at single-row headerless tables in latex format.
Admittedly a corner case, but specifying a column width with column_spec()
errors for headerless tables with a single row in LaTeX format.
Minimal reproducible example below.
library(kableExtra)
dat <- data.frame(x = 1, y = 1)
dat <- setNames(dat, NULL)
kbl(dat, format = "latex") |>
column_spec(2, latex_column_spec = "l")
#> Error in if (bold) {: missing value where TRUE/FALSE needed
Created on 2021-10-04 by the reprex package (v2.0.1)
I skimmed the code and I suspect that the issue is in column_spec_latex()
, where it gets a sequence of rows as:
rows <- seq(1 + off, nrows)
. With nrows = 1L
(correct) and off = 1
as well, it yields rows = c(2, 1)
and fails in the subsequent loop through the rows when it starts processing row number 2 which does not exist.
But I'm not sure what a proper fix would be, since I don't know the role played by off
in the general case.
I suspect this is related with #613.
Best wishes.