Immanuel Williams
Immanuel Williams

Reputation: 31

How do you embed R markdown code within R Markdown?

I am teaching students how to create/edit R markdown files. so I would like to have an R markdown template within my R markdown file. An example is below:

---
title: "file_check"
author: "James"
date: "8/7/2020"
output: html_document
---

Learn by copying this into blank .Rmd file:

---
title: "Template"
author: "Your Name"
date: "Specify Date"
output: html_document
---

This is how you plot 
```{r}
plot(1:10)
```

When I run this I obviously get errors but I know there has to be a fast/efficient way to do this since the R markdown website has this capability.

Upvotes: 0

Views: 163

Answers (1)

Waldi
Waldi

Reputation: 41210

You could use a text chunck :

---
title: "file_check"
author: "James"
date: "8/7/2020"
output: html_document
---

Learn by copying this into blank .Rmd file:
```{text} 
--- 
title: "Template" 
author: "Your Name"
date: "Specify Date"
output: html_document
---
```

This is how you plot 
```{r}
plot(1:10)
```

enter image description here

Upvotes: 1

Related Questions