楼主: oliyiyi
2496 0

R Markdown Quick Tour Overview [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
84105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

楼主
oliyiyi 发表于 2016-6-18 12:56:06 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
R Markdown Quick Tour

Overview

Creating documents with R Markdown starts with an .Rmd file that contains a combination of markdown (content with simple text formatting) and R code chunks. The .Rmd file is fed to knitr, which executes all of the R code chunks and creates a new markdown (.md) document which includes the R code and it’s output.

The markdown file generated by knitr is then processed by pandoc which is responsible for creating a finished web page, PDF, MS Word document, slide show, handout, book, dashboard, package vignette or other format.

This may sound complicated, but R Markdown makes it extremely simple by encapsulating all of the above processing into a single render function. Better still, RStudio includes a “Knit” button that enables you to render an .Rmd and preview it using a single click or keyboard shortcut.



Installation

You can install the R Markdown package from CRAN as follows:

install.packages("rmarkdown")

You can open a new .Rmd file in the RStudio IDE by going to File > New File > R Markdown…



Markdown Basics

Markdown is a simple formatting language designed to make authoring content easy for everyone. Rather than write in complex markup code (e.g. HTML or LaTex), you write in plain text with formatting cues. Pandoc uses these cues to turn your document into attractive output. For example, the file on the left shows basic Markdown and the resulting output on the right:




R Code Chunks

Within an R Markdown file, R Code Chunks can be embedded with the native Markdown syntax for fenced code regions. For example, the following code chunk computes a data summary and renders a plot as a PNG image:




Inline R Code

You can also evaluate R expressions inline by enclosing the expression within a single back-tick qualified with ‘r’. For example, the following code embeds R results as text in the output at right




Rendering Output

There are two ways to render an R Markdown document into it’s final output format. If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.

If you are not using RStudio then you simply need to call the rmarkdown::render function, for example:

rmarkdown::render("input.Rmd")

Note that both methods use the same mechanism; RStudio’s “Knit” button calls rmarkdown::render() under the hood.



Using Parameters

R Markdown documents can contain a metadata section that includes title, author, and date information as well as options for customizing output. For example, this metadata included at the top of an .Rmd file adds a table of contents and chooses a different HTML theme:

---title: "Sample Document"output:  html_document:    toc: true    theme: united---

You can add a params: field to the metadata to provide a list of values for your document to use. R Markdown will make the list available as params within any R code chunk in the report. For example, the file below takes a filename as a parameter and uses the name to read in a data set.


Parameters let you quickly apply your data set to new data sets, models, and parameters. You can set new values for the parameters when you call rmarkdown::render(),

rmarkdown::render("input.Rmd", params = list())

as well as when you press the “Knit” button:




Output Formats

You can create many types of output from a single .Rmd file. R Markdown has built in support for HTML, PDF, MS_Word, ODT, RTF, Markdown, and Github flavored Markdown documents; Beamer, slidy.js, ioslides, and reveal.js slideshows; and websites, dashboards, books, handouts, package vignettes, and Shiny apps. These formats can be specified in metadata, for example:

---title: "Sample Document"output: pdf_document---

And you can set sub-options to customize each formats:

---title: "Sample Document"output:  pdf_document:    toc: true    highlight: zenburn---

Multiple formats can be specified in metadata:

---title: "Sample Document"output:  html_document:    toc: true    theme: united  pdf_document:    toc: true    highlight: zenburn---

If you are using rmarkdown::render then you can pass a format name to render to select from the available formats. For example:

render("input.Rmd", "pdf_document")

You can also render all formats defined in an input file with:

render("input.Rmd", "all")


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:R Markdown Overview Quick Down Tour generated documents includes creating content

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-27 04:03