Why is kableExtra add_footnote() causing book down compilation to fail?

Viewed 179

I'm trying to build a PDF of the book at https://github.com/proback/BeyondMLR.

The .Rmd all seems to compile nicely, and bookdown spits out a knitted document. Tables (like below) with an add_footnote() step cause bookdown to throw an error.

Here's the R code chunk in the Rmd document:

Subject <- c(1,2,3,4,5,6)
`X (0 = home, 1 = work)` <- c(0,1,1,1,0,0)
`Y (number of cigarettes)` <- c(3,0,0,1,2,1)
ex3chp4 <- data.frame(Subject, `X (0 = home, 1 = work)`, 
                      `Y (number of cigarettes)`)
kable(ex3chp4, booktabs=T, 
      caption="A small subset of hypothetical data on Minnesota workplace rules on smoking.",
  col.names = c("Subject", "X (location)", "Y (cigarettes)")) %>%
kable_styling(full_width = F) %>%
add_footnote(c("X is 0 for home and 1 for work.", "Y is number of cigaretttes in a 2-hour period."), notation = "none")

With add_footnote() in, I get the following:

! Misplaced \omit.
\multispan ->\omit 
                   \@multispan 
l.2035 ...cript{} X is 0 for home and 1 for work.}
                                                  \\ 

I've commented out the add_footnote() in a previous table, and no error thrown.

If I run the R code above directly in the console, I get the following:

\begin{table}

\caption{A small subset of hypothetical data on Minnesota workplace rules on smoking.}
\centering
\begin{tabular}[t]{rrr}
\toprule{}
Subject & X (location) & Y (cigarettes)\\
\midrule{}
1 & 0 & 3\\
2 & 1 & 0\\
3 & 1 & 0\\
4 & 1 & 1\\
5 & 0 & 2\\
\addlinespace
6 & 0 & 1\\
\bottomrule{}
\multicolumn{3}{l}{\textsuperscript{} X is 0 for home and 1 for work.}\\
\multicolumn{3}{l}{\textsuperscript{} Y is number of cigaretttes in a 2-hour period.}\\
\end{tabular}
\end{table}

That looks like decent LaTeX output to me…

1 Answers

As documented here, you just need to install the knitr development version:

remotes::install_github('yihui/knitr')
Related