Compiling a report with bookdown I encounter difficulties in referencing tables generated with the huxtable package. For my work, LaTex/PDF, as well as an HTML version of the report, need to be created.
When rendering the document knitr::is_XXX_output() selects the optimal way to display the tables, see MWE:
```{r chunk-label, results='asis', fig.cap='chunk-caption'}
set.seed(1234)
dat <- data.frame(cond = factor(rep(c("A","B"), each=2)),
rating = c(rnorm(2),rnorm(2, mean=.8)))
hux <- as_hux(dat) %>%
set_caption('hux caption') %>%
set_label("tab:hux-label")
if (knitr::is_html_output()) {
print_html(hux) # output table html friendly (requires in chunk options "results='asis'")
}
if (knitr::is_latex_output()) {
hux
}
```
I am not sure whether it is recommended to use the caption and label commands provided by huxtable
set_caption('pipe caption') and set_label("tab:hux-label")
or knitr
chunk-label and fig.cap='chunk caption'
For figures, the latter works very well, but unfortunately not for tables.
The hook for "tab.cap" as discussed in following did not work well with bookdown and if PDF & HTML are needed. Using table caption on R markdown file using knitr to use in pandoc to convert to pdf
Help and recommendations are very much appreciated!