Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Create sections through a loop with knitr

$
0
0

See this reproducible example :

---
title: "test"
output: html_document
---

## foo

```{r}
plot(1:3)
```

## bar

```{r}
plot(4:7)
```

## baz

```{r}
plot(8:12)
```

I want to be able to automate the creation of these sections as I can't know how many they will be before going further in my analysis.

My input to get this would be :

my_list   <- list(foo = 1:3, bar = 4:7, baz = 8:12)
my_fun    <- plot
my_depth  <- 2

And the ideal answer (though I'm welcoming any improvement) would help me build a mdapply function so that I could just run:

```{r}
mdapply(X = my_list, FUN = my_fun, title_depth = my_depth)
```

And get the same output.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>