Passing Parameters to R Markdown

后端 未结 2 2029

I am trying to create a parameterized report in R Markdown based on the following tutorial: http://rmarkdown.rstudio.com/developer_parameterized_reports.html#passing-paramet

相关标签:
2条回答
  • 2020-12-08 18:08

    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

    0 讨论(0)
  • 2020-12-08 18:10

    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"))

    0 讨论(0)
提交回复
热议问题