我正在尝试根据以下教程在R Markdown中创建参数化报告:http://rmarkdown.rstudio.com/developer_parameterized_reports.html#passing-parameters
我正在尝试使用render从r控制台传递文件路径作为参数.像这样:
render('rmarkdownfile.rmd',params= list( client= "clientdata.csv"))
Run Code Online (Sandbox Code Playgroud)
我的markdown文件如下所示:
title: "Liquidity Report"
output: pdf_document
params: client:"clientdata.csv"
---
```{r plot, echo=FALSE, warning=FALSE}
cftest <- read.csv(params$client)
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,上面写着:
read.table中的错误(file = file,header = header,sep = sep,quote = quote,:'file'必须是字符串或连接调用:
即使我遵循本教程的步骤,Markdown似乎也没有识别参数.有没有人能够在R Markdown中成功使用参数?
此外,我正在遵循本教程的建议,并使用R Studio预览以及r markdown和knitr的最新版本.
感谢您的帮助!
拉斐尔
Pau*_*mes 10
我喜欢做的不仅是指定文件名,还指定参数化报告中的目录.
---
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 = F}
knitr::opts_chunk$set(echo = F,
                      warning = F,
                      message = F)
## Set options
options(scipen = 999, # prevent scientific notation on large numbers
        stringsAsFactors = F) # prevent R from turning everything to factors
## Pull in the data
dataset <- read.csv(paste(params$directory, params$file, sep = '/'))
```
Run Code Online (Sandbox Code Playgroud)
然后在渲染功能中,您可以:
rmarkdown::render('LiquidityReport.Rmd',
                  params = list(
                      directory   = '~/path/to/data',
                      file        = 'clientdata.csv')
                  )
Run Code Online (Sandbox Code Playgroud)
        在我的情况下它工作,只需要更改标题中的缩进和我的文件夹中可用的一些名称...
在这里我的 jnk.Rmd
---
title: "Liquidity Report"
output: pdf_document
params: 
  client: "NAMESPACE"
---
```{r plot, echo=FALSE, warning=FALSE}
cftest <- read.csv(params$client)
```
Run Code Online (Sandbox Code Playgroud)
这就是我在控制台中调用的内容: render('jnk.Rmd',params= list( client= "NAMESPACE"))