将参数传递给 R Markdown [英] Passing Parameters to R Markdown

查看:62
本文介绍了将参数传递给 R Markdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据以下教程在 R Markdown 中创建参数化报告:http://rmarkdown.rstudio.com/developer_parameterized_reports.html#passing-parameters

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-parameters

我正在尝试使用渲染将文件路径作为参数从 r 控制台传递.像这样:

I'm trying to pass a file path as a parameter from the r console using render. Like this:

render('rmarkdownfile.rmd',params= list( client= "clientdata.csv"))

我的 Markdown 文件如下所示:

and my markdown file looks like this:

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

但我收到一条错误消息:

But I get an error that says:

read.table(file=file, header=header, sep=sep, quote=quote, : 'file' must be a string or connection Calls 中的错误:

Eror in read.table(file=file, header=header, sep=sep, quote=quote, : 'file' must be a character string or connection Calls:

即使我按照教程的步骤操作,Markdown 似乎也无法识别参数.有没有人能够成功使用 R Markdown 中的参数?

It seems like Markdown is not recognizing the parameters even though I'm following the steps of the tutorial. Has anyone been able to successfully use parameters in R Markdown?

此外,我正在遵循教程的建议,并使用 R Studio 预览版以及 r markdown 和 knitr 的最新版本.

Also, I'm following the recommendations of the tutorial and am using the R Studio preview as well as the latest builds of r markdown and knitr.

感谢您的帮助!

拉斐尔

推荐答案

就我而言,它有效,只需更改标题中的缩进和文件夹中可用的一些名称...

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

这里是我的 jnk.Rmd

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

这就是我在控制台中调用的内容:render('jnk.Rmd',params= list(client="NAMESPACE"))

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

这篇关于将参数传递给 R Markdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆