library(dplyr, warn.conflicts = FALSE)
9 Tables
I did a lot of experimenting with tables when creating the L2C Master Descriptive Table website. I need to add notes on creating and working with tables in this chapter. I may also want to add it to the [appendix in R4Epi](https://www.r4epi.com/appendix-alternative-table-formats.
Useful websites:
9.1 Test table
Just quickly testing to see if it will download. Need to better document this in the future.
<- tribble(
key ~var, ~description,
"ml_age", "Participant's age at baseline.",
"ml_gender_f", "Participant's self-reported sex at baseline.",
"ml_race_f", "Participant's self-reported race at baseline.",
"ml_race_eth_4cat_f", "Participant's self-reported race at baseline. Collapsed into four categories.",
"ml_hispanic_f", "Participant's self-report of Hispanic ethnicity at baseline."
)
Initially, the code chunk above created a datatable version of the table.
```{r}
DT::datatable(
key,
colnames = c("Variable Name", "Variable Description")
)
```
When I tried to render the book, I got the following error:
Error: Functions that produce HTML output found in document targeting pdf output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your quarto file:
prefer-html: true
Note however that the HTML output will not be visible in non-HTML formats.
Execution halted
::kable(key) knitr
var | description |
---|---|
ml_age | Participant’s age at baseline. |
ml_gender_f | Participant’s self-reported sex at baseline. |
ml_race_f | Participant’s self-reported race at baseline. |
ml_race_eth_4cat_f | Participant’s self-reported race at baseline. Collapsed into four categories. |
ml_hispanic_f | Participant’s self-report of Hispanic ethnicity at baseline. |
9.2 Issues
- Why do I get
?@tbl-demographics-overall
and how do I fix it?- There may be other reasons why this error can occur, but I was getting it because Quarto doesn’t currently support table captions for datatables. You can, however, use figure captions for datatables.