我正在使用rmarkdown执行5个主要步骤:阅读,清理,转换,分析和即时。
我的计划是将每个步骤的代码分成一个或两个降价文件(.Rmd)。每个跟随.Rmd将作为外部文件调用到下一个.Rmd(即我想将每个步骤的.Rmd嵌入到下一个步骤中)。
我正在通过替换:
来嵌套.Rmd文件knitr::opts_chunk$set(echo = TRUE)
与
knitr::knit("**ABSOLUTE PATH TO PREVIOUS .Rmd FILE**")
当我在 knitr :: knit 行出现错误时,直到我的第3次嵌套,这才有效:
Error in file(file, "rt" ) Cannot open the connection calls: <Anonymous> … withVisible ->eval ->eval -> read.csv ->read.table -> file
注意:每次我引用绝对路径时都会引用任何内容,所以这不应该是问题。
任何人都可以指出正确的嵌套方式.Rmd到彼此?
最后,如果这个工作流程看起来很野蛮,我会欢迎任何有关架构的其他建议!我将嵌套的原因(而不是将所有内容放入大型R笔记本中)是:
答案 0 :(得分:0)
To combine multiple child Rmd files, I use a general Rmd one that call all childs. In that way, you can also decide not to show some of them with eval=FALSE
directly in this main file.
More info on https://yihui.name/knitr/demo/child/
The main file would look like any Rmd:
---
title: Modelling distribution of species in the Bay of Biscay
author: "StatnMap - Sébastien Rochette"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<!-- Content -->
```{r reading, child='Reading.Rmd', eval=TRUE}
```
```{r cleaning, child='Cleaning.Rmd', eval=TRUE}
```
```{r analysis, child='Analysis.Rmd', eval=TRUE}
```