forked from Manan100196/ST_558_Project3_GroupD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRender_files.Rmd
30 lines (24 loc) · 1.29 KB
/
Render_files.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
title: "Automate R markdown"
author: "Rohan Prabhune, Manan Shah"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE,eval=TRUE,message=FALSE,warning=FALSE)
```
# Automating R markdown
`out_params` is a vector of parameters which are used as input parameters to **main.Rmd** file. Since the `param` argument in `render()` function requires params to be a named list, we have converted each element of `out_params` to a named list using `lapply()` into `out_params_list`.
`out_filename` is a vector of output file names we want for each of the input parameter.
Since there are only six parameters, we decided to go with a for loop to iterate over the file names and vector of named lists to create six different .md files based on the type of article.
```{r automate}
library(rmarkdown)
out_params <- c("lifestyle","entertainment","bus","socmed","tech","world")
out_params_list = lapply(out_params, FUN = function(x){list(var = x)})
out_filename <- c("Lifestyle_analysis.md","Entertainment_analysis.md",
"Business_analysis.md","Social_media_analysis.md",
"Tech_analysis.md","World_analysis.md")
for (i in 1:6){
rmarkdown::render(input = "main.Rmd", output_file = out_filename[i],
params = out_params_list[[i]])
}
```