kbl Table reference in Sweave not linking

I am updating some code in an Sweave document that used xtable to create tables, and referenced them inline.
I wanted to use kable+kableExtra instead, but can't figure out how to get the inline table references to work. I first tried in the label argument (which is where it was in xtable), but that is not working. I also tried naming the code chunk, but that threw a "undefined references" latex error.
Advice? or should I stick with xtable?

MWE

\documentclass{article}
\usepackage{booktabs}
\begin{document}

<<>>=
library(kableExtra)
mtcars[1:5,] |>
  kbl(row.names = FALSE, caption="First five rows of data from the mtcars data set", 
      label = "cars", booktabs = TRUE, align = 'c')
@

Table~\ref{cars} shows stuff. 

\end{document}

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.