Rmarkdown 使用指南(简易版)

Elitasia

2020-09-12

主题

Rmarkdown内置主题

cerulean
cosmo
flatly
journal
lumen
paper
readable
sandstone
simplex
spacelab
united
yeti

prettydoc包中的主题

architect
cayman
hpstr
leonids
tactile

rmdformats包中的主题

material
readthedown
html_clean
html_docco

其他包

hrbrthemes
tufte
tint

output中的其他参数

输出格式

html_document 输出html格式
pdf_document 输出PDF格式
word_document 输出word格式

一般参数

??html_document查看在html格式下更多参数 toc: TRUE #目录
toc_float: TRUE #目录的形式
number_sections: TRUE #各个标题的数字标记
theme: readable #文档主题
css: css/styles.css #加入额外的CSS
df_print: paged #表格的形式
fig_caption: TRUE #图片设置
highlight:include “default”, “tango”, “pygments”, “kate”, “monochrome”, “espresso”, “zenburn”, “haddock”, and “textmate”. Pass NULL to prevent syntax highlighting.

注意:prettydoc包不能设置toc_float

代码框设置Chunk options

eval: Whether to evaluate a code chunk.是否运行代码

echo: Whether to echo the source code in the output document (someone may not prefer reading your smart source code but only results).是否在输出结果中显示代码

results: When set to ‘hide’, text output will be hidden; when set to ‘asis’, text output is written “as-is”, e.g., you can write out raw Markdown text from R code (like cat(‘Markdown is cool.’)). By default, text output will be wrapped in verbatim elements (typically plain code blocks). 是否在输出结果中显示结果

collapse: Whether to merge text output and source code into a single code block in the output. This is mostly cosmetic: collapse = TRUE makes the output more compact, since the R source code and its text output are displayed in a single output block. The default collapse = FALSE means R expressions and their text output are separated into different blocks.是否将文本输出和源代码合并到输出中的单个代码块中。 这主要是美观的: collapse=TRUE使输出更紧凑,因为R源代码及其文本输出显示在单个输出块中。 默认的 collapse=FALSE表示R表达式及其文本输出分为不同的块。

warning, message, and error: Whether to show warnings, messages, and errors in the output document. Note that if you set error = FALSE, rmarkdown::render() will halt on error in a code chunk, and the error will be displayed in the R console. Similarly, when warning = FALSE or message = FALSE, these messages will be shown in the R console.

include: Whether to include anything from a code chunk in the output document. When include = FALSE, this whole code chunk is excluded in the output, but note that it will still be evaluated if eval = TRUE. When you are trying to set echo = FALSE, results = ‘hide’, warning = FALSE, and message = FALSE, chances are you simply mean a single option include = FALSE instead of suppressing different types of text output individually. 是否在输出文档中包括代码块中的任何内容。 当include=FALSE时,整个代码块将排除在输出中,但请注意,如果eval = TRUE,仍将对其进行求值。 当您尝试设置echo = FALSE,结果=‘hide’,warning=FALSE和message=FALSE时,您可能只是意味着一个单独的选项包括= FALSE,而不是分别禁止显示不同类型的文本。

cache: Whether to enable caching. If caching is enabled, the same code chunk will not be evaluated the next time the document is compiled (if the code chunk was not modified), which can save you time. However, I want to honestly remind you of the two hard problems in computer science (via Phil Karlton): naming things, and cache invalidation. Caching can be handy but also tricky sometimes. 是否启用缓存。 如果启用了缓存,则下次编译文档时(如果未修改代码块)将不评估同一代码块,从而可以节省时间。 但是,我想诚实地提醒您(通过Phil Karlton)计算机科学中的两个难题:命名事物和缓存无效化。 缓存可能很方便,但有时也很棘手。

fig.width and fig.height: The (graphical device) size of R plots in inches. R plots in code chunks are first recorded via a graphical device in knitr, and then written out to files. You can also specify the two options together in a single chunk option fig.dim, e.g., fig.dim = c(6, 4) means fig.width = 6 and fig.height = 4. R图形的(图形设备)大小,以英寸为单位。 代码块中的R图首先通过knitr中的图形设备记录,然后写出到文件中。 您还可以在单个块选项fig.dim中一起指定两个选项,例如,fig.dim = c(6,4)表示fig.width = 6和fig.height = 4。

out.width and out.height: The output size of R plots in the output document. These options may scale images. You can use percentages, e.g., out.width = ‘80%’ means 80% of the page width. 输出文档中R图的输出大小。 这些选项可以缩放图像。 您可以使用百分比,例如out.width = ’80%’表示页面宽度的80%。

fig.align: The alignment of plots. It can be ‘left’, ‘center’, or ‘right’. 图的对齐,可以为“左”、“中”、“右”。

dev: The graphical device to record R plots. Typically it is ‘pdf’ for LaTeX output, and ‘png’ for HTML output, but you can certainly use other devices, such as ‘svg’ or ‘jpeg’. 用于记录R图的图形设备。 通常,对于LaTeX输出,它是’pdf’,对于HTML输出是’png’,但是您当然可以使用其他设备,例如’svg’或’jpeg’。

fig.cap: The figure caption. 图形标题

child: You can include a child document in the main document. This option takes a path to an external file. 您可以在主文档中包含子文档。 此选项采用到外部文件的路径。

正文

标题

几个#代表第几级标题,#之后一定要空一格

字体

两个 ** 中间夹斜体
斜体
四个 **** 中间夹粗体
粗体
六个 ****** 中间夹斜粗体
斜粗体

引用

用“>”表示,>后面要空格,前面要空排

“I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him.”

— Mark Twain

“世上本没有路,走的人多了,也便成了路。”

—鲁迅

代码

代码

列表

有序列表

有序列表:
1. 第一行
2. 第二行
3. 第三行

无序列表

无序列表:
* 第一行
* 第二行

制表

商品价格表
商品 价格
毛巾 5
酸奶 6
表的代码

表的代码

插入图片和链接

插入图片

代码

代码

发布

发布到RPubs时,文件名以英文命名,路径名也要是英文!