How to deploy kable table latex format in markdown

Viewed 101

I need to create a lot of kable tables so i use a for loop and store this tables in a list, but when I try to deploy the kable table from the list in markdown, the result is the latex code, not a pdf, what can I do to solve it?

table <- data.frame(col1 = c(1:30), col2 = c(rep(a, 10), rep(b, 10), rep(c, 10)))

t_list <- list()

for (letter in unique(table$col2)){
    a <- table %>% filter(col2 == letter)
    aa <- a %>% kbl()
    t_list <- append(t_list, aa)
}

# R Markdown ------------------
\```{r}
t_list[[1]]
\```

# output in latex not in pdf

Thanks

1 Answers

The solution should be relatively simple, by asking the output inline (r t_list[[1]]), and not within an R code chunk. Like this, I was able to reproduce your code and produce a PDF printing the first table, as in your code above:

```{r}
table <- data.frame(col1 = c(1:30), col2 = c(rep("a", 10), rep("b", 10), rep("c", 10)))

t_list <- list()

for (letter in unique(table$col2)){
    a <- table %>% filter(col2 == letter)
    aa <- a %>% kbl() %>%
kable_styling(latex_options = "striped")
    t_list <- append(t_list, aa)
    aa
}
```

# R Markdown ------------------
`r t_list[[1]]`

See this image as a quick example: PDF output

Hope this helps, but please do let me know if it doesn't.

Related