purrr headings with rmarkdown

Hi, is there a way to generate headings using purrr in rmarkdown documents?

For example with this code in a chunk:

library(tidyverse)

cats <- unique(iris$Species) %>% 
  set_names() 

plots <- function(cat){
  ggplot(iris %>% filter(Species == cat),
              aes(Sepal.Length, Sepal.Width)) +
        geom_point()
}


purrr::map(cats, ~plots(.x))

But with markdown headings in between e.g. (# setosa) - something like this:

I thought I remembered seeing a function in either purrr or rmarkdown that would do something like this, but I can't find it. Any ideas?

This is what I was after: 14.7 Use knitr::knit_expand() to generate Rmd source | R Markdown Cookbook

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.