仅从Rmd文档中提取文本 [英] Extract only text from Rmd documents

查看:108
本文介绍了仅从Rmd文档中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

甚至不确定是否可行,但是是否有办法仅提取.Rmd文件的原始文本部分并丢弃任何代码? 还是基本上将.Rmd文件转换为R中的.txt文件?

Not even sure if this is possible, but is there a way to extract only the raw text portion of the .Rmd file and discard any code? Or basically converting an .Rmd file into .txt file within R?

我已经尝试过函数readLines,但这会使所有(对我来说)无用的元数据变得毫无用处.

I've tried the function readLines, but this makes a huuuuuge character with all kinds of (to me) useless meta-data.

推荐答案

您可以knit文档而无需评估和包含代码.

You can knit document without evaluating and including code.

这是虚拟文档foo.Rmd的示例:

#标头1

# Header 1

foo

##标头2

##标头22

foobar

```{r}
1
```

```{r}
1
```

文字文字文字

```{r}
打印(2)
```

```{r}
print(2)
```

我们可以使用knitr::knit("foo.Rmd")编织此文档,但是在这种情况下,代码块将包含在文本中.为了解决这个问题,我们需要设置knitr选项:

We can knit this document using knitr::knit("foo.Rmd"), but in this case code chunks will be included in text. To deal with this we need to set knitr options:

library(knitr)
opts_chunk$set(list(echo = FALSE, eval = FALSE))
knit("foo.Rmd")

此命令将仅使用文本创建输出文档foo.md.

This command will create output document foo.md only with text.

这篇关于仅从Rmd文档中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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