如何从RMarkdown (.Rmd)文件中提取所有的代码块并将它们转储到普通的 R 脚本中?
基本上,我想要执行这个问题中描述的互补操作,该操作使用代码块选项仅提取 Rmd 的文本部分(即非代码部分)。
因此,具体来说,我想要从像以下这样的 Rmd 文件:
---
title: "My RMarkdown Report"
author: "John Appleseed"
date: "19/02/2022"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.
For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
Some text description here.
```{r cars}
a = 1
print(a)
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Some more comments here.
将上述代码部分提取到一个包含R脚本的文件中,如下所示:
knitr::opts_chunk$set(echo = TRUE)
a = 1
print(a)
summary(cars)
plot(pressure)