怎么把.Rmd文件转换成Rstudio的.Rnw文件? [英] How to convert .Rmd file to .Rnw file of Rstudio?

查看:280
本文介绍了怎么把.Rmd文件转换成Rstudio的.Rnw文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢在Rstudio中使用knitr,并且一直使用它来编写降价演示文稿和数据分析.我想使用相同的代码并在论文中得出结果,并且想要将Rmd文件```{r}中的代码块转换为Rnw文件<< >>= @中的块.

I really like using knitr in Rstudio and have been using it to write markdown presentations and data analysis. I want to use the same code and results in a paper and want to convert the code chunks in Rmd file ```{r} to the chunks of Rnw file << >>= @.

这也允许使用相同的文档和编写的代码来表示主要论文.

This allows using the same document and code written for presentation for the main paper as well.

有没有一种方法可以在markdown和Rnw文件的代码块之间进行转换?

Is there a way of converting between code chunks of markdown and Rnw files ?

或整个文件本身,除了代码块的语法不同之外,它们在标记中非常相似(使用pandoc可以轻松地将文本转换为乳胶)

or the entire file itself as apart from the difference in syntax of code chunks, they are quite similar in the markup (converting the text to latex is easy with say pandoc)

推荐答案

您无需外部转换整个文档,而只需将R代码外部化即可在不同文档之间共享.参见 http://yihui.name/knitr/demo/externalization/

Instead of converting the whole document, you can just externalize your R code so it can be shared across different documents; see http://yihui.name/knitr/demo/externalization/

一旦有了read_chunk('Rcode.r'),就可以在Rmd中使用```{r label},在Rnw文档中使用<<label>>=,其中label来自R脚本中的行## @knitr label.

Once you have read_chunk('Rcode.r'), you can use ```{r label} in your Rmd and <<label>>= in your Rnw document, where label comes from the line ## @knitr label in the R script.

这篇关于怎么把.Rmd文件转换成Rstudio的.Rnw文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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