9  Tables

library(dplyr, warn.conflicts = FALSE)

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.

key <- tribble(
 ~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
knitr::kable(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.

9.2 Issues