Jaskeil
Jaskeil

Reputation: 1232

Passing multiple parameters in RMarkdown document

I am looking to pass multiple parameters in my RMarkdown document. I have the following as an example:

mvndr_nm <- c('name1', 'name2', 'name3', 'name4', 'name5', 'name6')

I also have

mvndr_nbr<- c('60031167', '60688509', '60074051', '60148060', '60086898', '60080204')

I created a unique Markdown document using params and a loop that prints each out doing the following:

for (i in c('60031167', '60688509', '60074051', '60148060', '60086898', '60080204')) {
  rmarkdown::render("C:/Users/santi/Documents/R Scripts/Export_Data_CSV.Rmd", 
                    output_file = sprintf("MVNDR_%s.html", i),
                    params = list(MVNDR_NBR = i))
}

My print out look as such, I would like the first circle to actually be the names, instead of numbers. I tired to do that in the comment below, however it did not show the name despite calling the params function. Below the image is my logic :

enter image description here

---
title: "`r params$MVNDR_NBR`"
author: "Santiago Canon"
date: "5/26/2021"
output: 
  html_document:
    highlight: monochrome
    theme: flatly
params:
  MVNDR_NBR: sample_vendor_tbl$MVNDR_NBR
  MVNDR_NM: vendor_nm$MVNDR_NM
  
---


<font size="4"> This document will provide a summary of "`r params$MVNDR_NM`" performance within in QC: </font>

To be clear what I simply want is to pass the names through the title and some comments I will make it in the document. It works perfectly fine with the numbers but not the names

Upvotes: 0

Views: 799

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388797

RMD file -

---
title: "`r params$MVNDR_NBR`"
author: "Santiago Canon"
date: "5/26/2021"
output: 
  html_document:
    highlight: monochrome
    theme: flatly
params:
  MVNDR_NBR: NA
  MVNDR_NM: NA
  
---


<font size="4"> This document will provide a summary of "`r params$MVNDR_NM`" performance within in QC: </font>

for loop -

mvndr_nm <- c('name1', 'name2', 'name3', 'name4', 'name5', 'name6')
mvndr_nbr<- c('60031167', '60688509', '60074051', '60148060', '60086898', '60080204')


for (i in seq_along(mvndr_nm)) {
  rmarkdown::render("C:/Users/santi/Documents/R Scripts/Export_Data_CSV.Rmd", 
                    output_file = sprintf("MVNDR_%s.html", mvndr_nbr[i]),
                    params = list(MVNDR_NBR = mvndr_nbr[i], MVNDR_NM = mvndr_nm[i]))
}

Output -

MVNDR_60031167.html

enter image description here

MVNDR_60688509.html -

enter image description here

Upvotes: 3

Related Questions