I have this:
# Title 1
```{r}
barplot(mtcars$mpg)
```
text describing plot 1
# Title 2
```{r}
barplot(mtcars$mpg)
```
text describing plot 2
# Title 3
```{r}
barplot(mtcars$mpg)
```
text describing plot 3
As you see, the unit of repetition is:
# Title x
```{r}
barplot(mtcars$mpg)
```
text describing plot x
Is there a way to create a function that generates this unit of repetition?
Expected input that equals what I have above:
```{r}
function_that_creates_title_graph_text(1)
function_that_creates_title_graph_text(2)
function_that_creates_title_graph_text(3)
Try working from this
suppressPackageStartupMessages({
library(glue)
})
cpar <- ")"
fence <- "```"
lang <- "{{r}}"
lpar <- "("
nl <- "\n"
ptype <- "barplot"
text <- "text describing plot "
title <- "# Title "
block_out <- function(x, ptype, y, z) {
glue(title,x,nl,nl,fence,lang,nl,ptype,lpar,y,"$",z,cpar,nl,fence,nl,nl,text,x)
}
block_out(1,"barplot","mtcars","mpg")
#> # Title 1
#>
#> ```{r}
#> barplot(mtcars$mpg)
#> ```
#>
#> text describing plot 1
cderv
May 26, 2021, 9:10am
3
Here are some recipes to help with this kind of task
This book showcases short, practical examples of lesser-known tips and tricks to helps users get the most out of these tools. After reading this book, you will understand how R Markdown documents are transformed from plain text and how you may...
This book showcases short, practical examples of lesser-known tips and tricks to helps users get the most out of these tools. After reading this book, you will understand how R Markdown documents are transformed from plain text and how you may...
The second one is about knitr::knit_expand
which is like glue
and allow to generate Rmd source easily
Hope it helps
system
Closed
June 16, 2021, 9:10am
4
This topic was automatically closed 21 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.