R Markdown,Knitr,Pandoc和Bookdown之间的关系 [英] Relationship between R Markdown, Knitr, Pandoc, and Bookdown

查看:95
本文介绍了R Markdown,Knitr,Pandoc和Bookdown之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R Markdown,Knitr,Pandoc和Bookdown的功能之间有什么关系?

What is the relationship between the functionality of R Markdown, Knitr, Pandoc, and Bookdown?

在将带有嵌入式R代码(例如.Rnw.Rmd)的标记文档转换为最终输出(例如.pdf.html)时,这些软件包之间的分工"具体是什么?而且,如果使用Knitr处理RMarkdown,则rmarkdown程序包有什么作用?与markdown package有何不同?

Specifically what is the 'division of labour' between these packages in converting markup documents with embedded R code (e.g. .Rnw or .Rmd) into final outputs (e.g. .pdf or .html)? And if Knitr is used to process RMarkdown, what does the rmarkdown package do and how is it different to the markdown package?

推荐答案

Pandoc

Pandoc是一个文档转换器.它可以从许多不同的标记格式转换为许多其他格式,例如.doc.pdf等.

Pandoc是没有GUI的命令行工具.它是独立于R的独立软件.但是,它与R Studio捆绑在一起,因为rmarkdown依赖它进行文档转换.

Pandoc is a command line tool with no GUI. It is an independent piece of software, separate from R. However, it comes bundled with R Studio because rmarkdown relies on it for document conversion.

Pandoc不仅可以转换文档,还可以在基本Markdown语言的基础上添加功能,使其能够支持更复杂的输出.

Pandoc not only converts documents, but it also adds functionality on top of the base markdown language to enable it to support more complex outputs.

R Markdown基于Markdown:

R Markdown is based on markdown:

Markdown是一种轻量级的标记语言,具有纯文本格式语法,旨在将其转换为HTML和许多其他格式.降价文件是纯文本文件,通常具有扩展名.md.

Markdown is a lightweight markup language with plain text formatting syntax designed so that it can be converted to HTML and many other formats. A markdown file is a plain text file that is typically given the extension .md.

与其他标记语言(例如HTML和Latex)一样,它完全独立于R.

Like other markup languages like HTML and Latex, it is completely independent from R.

没有明确定义的Markdown标准.这导致了碎片化,因为不同的供应商编写了自己的语言变体来纠正缺陷或添加缺少的功能.

There is no clearly defined Markdown standard. This has led to fragmentation as different vendors write their own variants of the language to correct flaws or add missing features.

markdown 是可转换.Rmd文件转换为HTML.它是 rmarkdown 的前身,它提供了更多的功能功能.不再建议使用.

markdown is an R package which converts .Rmd files into HTML. It is the predecessor of rmarkdown, which offers much more functionality. It is no longer recommended for use.

R Markdown是markdown语法的扩展. R Markdown文件是纯文本文件,通常具有文件扩展名.Rmd.它们是使用markdown语法的扩展编写的,该扩展使R代码可以以稍后可以执行的方式嵌入其中.

R Markdown is an extension of the markdown syntax. R Markdown files are plain text files that typically have the file extension .Rmd. They are written using an extension of markdown syntax that enables R code to be embedded in them in a way which can later be executed.

由于预期它们将由rmarkdown软件包处理,因此可以使用 Pandoc markdown语法作为R markdown文件的一部分.这是对原始markdown语法的扩展,该语法提供了其他功能,例如原始HTML/Latex和表.

Because they are expected to be processed by the rmarkdown package, it is possible to use Pandoc markdown syntax as part of a R markdown file. This is an extension to the original markdown syntax that provides additional functionality like raw HTML/Latex and tables.

R包rmarkdown是一个库,可以处理.Rmd文件并将其转换为多种不同的格式.

The R package rmarkdown is a library which proceses and converts .Rmd files into a number of different formats.

核心功能是rmarkdown::render潘多克(pandoc).此功能使用pandoc将输入文件渲染为指定的输出格式.如果输入需要编织,则在pandoc之前调用knitr::knit.

The core function is rmarkdown::render which stands on the shoulders of pandoc. This function 'renders the input file to the specified output format using pandoc. If the input requires knitting then knitr::knit is called prior to pandoc.

RMarkdown软件包的目标只是提供合理的默认值和R友好的界面,可自定义Pandoc选项..

The RMarkdown package's aim is simply to provide reasonably good defaults and an R-friendly interface to customize Pandoc options..

RMarkdown文件顶部显示的YAML元数据专门用于将选项传递给rmarkdown::render,以指导构建过程.

The YAML metadata seen at the top of RMarkdown files is specificially to pass options to rmarkdown::render, to guide the build process.

请注意,RMarkdown仅处理markdown语法.如果要转换.Rhtml.Rnw文件,则应使用Knitr内置的便捷功能,例如knitr::knit2htmlknitr:knit2pdf

Note that RMarkdown only deals with markdown syntax. If you want to convert a .Rhtml or a .Rnw file, you should use the convenience functions built into Knitr, such as knitr::knit2html and knitr:knit2pdf

Knitr提取一个带有嵌入式代码的纯文本文档,执行该代码并将结果编织"回文档中.

Knitr takes a plain text document with embedded code, executes the code and 'knits' the results back into the document.

例如,它将转换

  • An R Markdown (.Rmd) file into a standard markdown file (.md)
  • An .Rnw (Sweave) file into to .tex format.
  • An .Rhtml file into to html.

核心功能是knitr::knit,默认情况下,它将查看输入文档并尝试猜测它是什么类型-Rnw,Rmd等.

The core function is knitr::knit and by default this will look at the input document and try and guess what type it is - Rnw, Rmd etc.

此核心功能执行三个角色: -源解析器,它查看输入文档并检测哪些部分是用户要评估的代码. -一个代码评估程序,它评估此代码 -输出渲染器,它以原始输出类型可以解释的格式将评估结果写回到文档中.例如,如果输入文件是.Rmd,则输出呈现标记为.md格式的代码评估输出.

This core function performs three roles: - A source parser, which looks at the input document and detects which parts are code that the user wants to be evaluated. - A code evaluator, which evaluates this code - An output renderer, which writes the results of evaluation back to the document in a format which is interpretable by the raw output type. For instance, if the input file is an .Rmd, the output render marks up the output of code evaluation in .md format.

Knitr不会在文档格式之间进行转换,例如将.md转换为.html.但是,它确实提供了一些方便的功能来帮助您使用其他库来执行此操作. 如果使用的是rmarkdown软件包,则应忽略此功能,因为它已被rmarkdown::render取代.

Knitr does not convert between document formats - such as converting a .md into a .html. It does, however, provide some convenience functions to help you use other libraries to do this. If you are using the rmarkdown package, you should ignore this functionality because it has been superceded by rmarkdown::render.

一个示例是knitr:knit2pdf,它会:编织输入Rnw或Rrst文档,然后使用texi2pdf或rst2pdf'编译为PDF.

knitr::knit2html可能是造成混乱的原因,它是编织的便捷功能输入降价源并调用markdown::markdownToHTML将结果转换为HTML." 这是旧版功能,因为markdown软件包已被rmarkdown软件包取代.请参阅本说明.

A potential source of confusion is knitr::knit2html, which "is a convenience function to knit the input markdown source and call markdown::markdownToHTML to convert the result to HTML." This is now legacy functionality because the markdown package has been superceded by the rmarkdown package. See this note.

bookdown软件包建立在R Markdown之上,并继承了Markdown语法的简单性以及多种输出格式(PDF/HTML/Word/…)的可能性.

The bookdown package is built on top of R Markdown, and inherits the simplicity of the Markdown syntax , as well as the possibility of multiple types of output formats (PDF/HTML/Word/…).

它提供的功能包括多页HTML输出,编号和交叉引用图形/表格/节/方程,插入部件/附录以及导入GitBook样式(

It offers features like multi-page HTML output, numbering and cross-referencing figures/tables/sections/equations, inserting parts/appendices, and imported the GitBook style (https://www.gitbook.com) to create elegant and appealing HTML book pages.

这篇关于R Markdown,Knitr,Pandoc和Bookdown之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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