I am trying to make a reproducible "data dictionary" in RMarkdown to ease my job of describing the various undocumented data sets I work with. I've looked at the most related post here: Programmatically insert text, headers and lists with R markdown, but am running into problems. I have a data.frame that has the colnames from my dataset and a column of strings that describe each variable. When I knit my RMarkdown document, I get one formatted header for the first variable and the rest show up with the formatting hash marks (##) and the variable name, but not as a formatted header.
```{r, results = 'asis'}
varnames <- c("A", "B", "C")
vardesc <- c("A is this.", "B is this.", "C is this.")
df <- data.frame(varnames, vardesc)
for(i in 1:nrow(df)) {
cat("##", df$vars[i], " \n")
cat("Description: ", df$vardesc[i])
cat(" \n")
}
```
This gives me variable "A" is a formatted header only. It seems my rookie knowledge of functions could be to blame but I can't figure out what I am doing wrong.
My output is as follows (with A being formatted and the rest not formatted):
## A
Description:
A is this.
## B
Description:
B is this.
## C
Description:
C is this.
Any advice would be greatly appreciated. I'm open to other methods to do this if they exist.