一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

RStudio

 上通下達 2013-03-19

R Markdown

Overview

R Markdown is a format that enables easy authoring of reproducible web reports from R. It combines the core syntax of Markdown (an easy-to-write plain text format for web content) with embedded R code chunks that are run so their output can be included in the final document.

The concept of R Markdown is similar to Sweave (a system built-in to R for combining R with LaTeX). In Sweave, Rnw files are "weaved" into TeX files that are then compiled into PDFs. In R Markdown, Rmd files are similarly "weaved" into plain markdown (.md) files that are then compiled into HTML documents.

The R Markdown syntax is described in detail below. At a high-level it is a combination of the following:

  • The core Markdown syntax
  • The ability to embed R code and the results of its execution
  • Additional extensions provided by the Sundown library
  • Support for LaTeX and MathML equations
  • Bundling of images within generated HTML files

Implementation

The implementation of R Markdown is provided by two packages:

  • knitr — Weaves Rmd files into plain markdown (.md) files
  • markdown — Converts markdown files into HTML documents

For example, to run the R code chunks inside an Rmd file and then convert the resulting markdown file into HTML you would execute the following:

library(knitr)
library(markdown)
knit("Foo.Rmd")
markdownToHTML("Foo.md", "Foo.html")

Note that this can also be accomplished in one step by calling knitr::knit2html. However, the fact that converting from Rmd to HTML is broken into two steps allows for the use of alternate markdown rendering programs (e.g. Pandoc).

RStudio also implements support for rendering R Markdown files into HTML using the Knit HTML commands. This produces a result equivalent to the above code.

Syntax

The following is a detailed description of the R Markdown syntax. Note that the first two sections covering Core Markdown and R Code Chunks are always applicable. The remaining sections apply to the rendering of markdown to HTML as implemented by RStudio and the markdown package. If you are using an alternate markdown program such as Pandoc please consult its documentation for information on comparable extensions.

Core Markdown

The core markdown syntax defines plain-text formatting commands for a wide variety of constructs including headers, phrase emphasis, ordered and unordered lists, links, images, and inline code. R Markdown implements all of the core markdown syntax (with two exceptions noted below in the Github/Sundown Extensions section).

Please reference the core markdown syntax definition for a detailed description of supported elements.

Embedded R Code

Within an R Markdown file, R code chunks can be embedded using fenced code regions:

```{r}
1 + 1
```

R code chunks can also have a label and specify processing options:

```{r md-cars-scatter, message=FALSE, fig.width=7, fig.height=5}
library(ggplot2)
qplot(hp, mpg, data=mtcars)+geom_smooth() 
```

You can also evaluate R expressions inline by enclosing the expression within a single back-tick qualified with 'r'. For example:

I counted `r 1 + 1` red trucks on the highway.

When R code is displayed in the resulting HTML file, it is given a distinct background color and syntax highlighted. Textual output resulting from R code is shown within a bordered frame.

Sundown Extensions

The markdown package uses the Sundown library for rendering markdown to HTML (Sundown is a project maintained by Github). Sundown supports core markdown, a set of extensions known as Github flavored markdown, as well several other extensions.

The Github flavored markdown extensions include:

  • Multiple underscores in words (e.g. perform_complicated_task) are not treated as formatting
  • URLs are automatically linked
  • Fenced code regions using ```

Additional extensions include:

  • Pandoc title blocks and YAML front-matter at the top of documents is ignored
  • Support for tables using the syntax defined by PHP Markdown Extra.
  • Superscripts (e.g. superscript^2)
  • Strikethrough (e.g. ~~strikethrough~~)

Finally, selected ASCII character sequences are converted into typographic HTML entities:

  • Straight quotes ( " and ' ) into “curly” quotes
  • Backtick quotes (``like this'') into “curly” quotes
  • Dashes (“--” and “---”) into en- and em-dash entities
  • Three consecutive dots (“...”) into an ellipsis entity
  • Fractions 1/4, 1/2, and 3/4 into ?, ?, and ?
  • Symbols (c), (tm), and (r) into ?, ?, and ?

LaTeX and MathML Equations

You can embed LaTeX or MathML equations in R Markdown files using the following syntax:

  • $equation$ for inline equations (note there must not be whitespace adjacent to the $ delimiters)
  • $$ equation $$ for display equations
  • <math ...> </math> for MathML equations.

The article on Equations in R Markdown includes more detailed information on embedded equations.

Image Bundling

When converting from markdown to HTML, images that are referenced using relative hrefs are bundled directly into the generated HTML file. This creates a standalone web page that can be shared without needing to package up any additional files. You can attach the HTML file to an email, share it using a public folder, or deploy it to a web server as a single HTML file.

Image bundling is performed by base64 encoding the image and then inlining the encoded image using a data URI.

Text Encoding

The Sundown library reads and writes content using UTF-8 encoding. It is therefore most convenient to use UTF-8 as the encoding for Rmd files. Note that RStudio supports the use of other encodings for Rmd files (it converts them to UTF-8 prior to sending them to Sundown) however if you are using the markdown package directly you'll need to perform this conversion manually.

Related Topics

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    91亚洲熟女少妇在线观看| 免费在线成人午夜视频| 日韩精品中文在线观看| 欧美精品日韩精品一区| 久久国产精品亚州精品毛片| 亚洲欧美日韩国产自拍| 日本不卡一本二本三区| 69精品一区二区蜜桃视频| 日韩欧美第一页在线观看| 日韩精品免费一区三区| 日韩一区二区三区在线日| 午夜久久精品福利视频| 欧美日韩最近中国黄片| 亚洲a码一区二区三区| 久久精品色妇熟妇丰满人妻91| 在线免费视频你懂的观看 | 亚洲国产精品国自产拍社区| 激情亚洲内射一区二区三区| 日韩欧美91在线视频| 精品推荐国产麻豆剧传媒| 日本人妻的诱惑在线观看| 都市激情小说在线一区二区三区| 九九热在线免费在线观看| 97人妻精品一区二区三区男同| 日韩成人中文字幕在线一区 | 欧美一区二区不卡专区| 国产成人亚洲精品青草天美| 亚洲欧美精品伊人久久| 亚洲日本中文字幕视频在线观看 | 国产一区二区三中文字幕| 四季精品人妻av一区二区三区 | 视频在线播放你懂的一区| 久久黄片免费播放大全 | 热久久这里只有精品视频| 欧美黑人精品一区二区在线| 亚洲视频偷拍福利来袭| 日韩人妻欧美一区二区久久| 爱草草在线观看免费视频| 国产内射一级一片内射高清视频| 99国产高清不卡视频| 欧美日韩综合在线第一页|