Passing Parameters to R Markdown

What I like to do is not just specify a file name but also a directory on my parameterized reports.

---
title: Liquidity Report
date: '`r strftime(Sys.time(), format = "%B %d, %Y")`'
output:
  pdf_document:
    number_sections: yes
    theme: cerulean
    toc: yes
    toc_depth: 2
params:
  directory:
    value: x
  file:
    value: x
---

```{r, include = FALSE}
knitr::opts_chunk$set(
      echo    = FALSE
    , warning = FALSE
    , message = FALSE
)

## Pull in the data
dataset <- read.csv(file.path(params$directory, params$file))
```

And then in your render function you can:

rmarkdown::render(
      input  = 'LiquidityReport.Rmd'
    , params = list(
          directory = '~/path/to/data'
        , file      = 'clientdata.csv'
        )
)

The knitr docs can add more information: > ?knitr::knit_params


In my case it worked, just had to change the indentation in the header and some names which are available in my folder...

Here my jnk.Rmd

---
title: "Liquidity Report"
output: pdf_document
params: 
  client: "NAMESPACE"
---
```{r plot, echo=FALSE, warning=FALSE}
cftest <- read.csv(params$client)
```

And this is what I called in the console : render('jnk.Rmd',params= list( client= "NAMESPACE"))

Tags:

R

R Markdown