是否可以从RStudio中的R markdown(.Rmd)调用外部R脚本? [英] Is it possible to call external R script from R markdown (.Rmd) in RStudio?
本文介绍了是否可以从RStudio中的R markdown(.Rmd)调用外部R脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照此R Sweave示例加载外部R脚本是相当简单的:
It's fairly trivial to load external R scripts as per this R Sweave example:
<<external-code, cache=FALSE>>=
read_chunk('foo-bar.R')
@
R Markdown是否可以做同样的事情?
Can the same be done for R Markdown?
推荐答案
是.
将其放在R Markdown文件的顶部:
Put this at the top of your R Markdown file:
```{r setup, echo=FALSE}
opts_chunk$set(echo = FALSE, cache=FALSE)
read_chunk('../src/your_code.R')
```
使用以下提示为knitr
分隔代码(就像@yihui在示例):
Delimit your code with the following hints for knitr
(just like @yihui does in the example):
## @knitr part1
plot(c(1,2,3),c(1,2,3))
## @knitr part2
plot(c(1,2,3),c(1,2,3))
现在,您可以在R Markdown文件中对代码段进行在线评估:
In your R Markdown file, you can now have the snippets evaluated in-line:
Title
=====
Foo bar baz...
```{r part1}
```
More foo...
```{r part2}
```
这篇关于是否可以从RStudio中的R markdown(.Rmd)调用外部R脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文