I have a long questionnaire with long questions. I want to print the data for
each subject. I need a table of contents so I know the page number on which
each subject's data begin.
I'm using Quarto with a reference doc to which I've added the page number
field.
Currently the only way I can get the subject into the TOC is to print each table
separately.
I'm using mtcars as an example. (The car models represent the subjects.)
title: "example"
execute:
echo: false
format:
docx:
reference-doc: custom-reference-doc.docx
toc: true
library(tidyverse)
# I have lots of columns with very long column headers in my example so the
# only way I can display the data is vertically.
mtcars1 <- mtcars |>
rownames_to_column("Model") |>
pivot_longer(cols = !Model,
names_to = "Feature")
models <- row.names(mtcars)
per_model <- vector("list", length(models))
for (i in seq_along(models)) {
per_model[[i]] <- mtcars1 |>
filter(Model == models[[i]]) |>
gt::gt()
}
Can I put the remainder of this in a loop and still get the Model in the TOC?
Model r models[[1]]
per_model[[1]]
Model r models[[2]]
per_model[[2]]
etc.
Maybe I should use knitr::kable(), rather than gt()?