主页 https://rmarkdown.rstudio.com
易辉 https://yihui.name/cn/
https://garrettgman.github.io/rmarkdown/articles.html
knitr https://github.com/yihui/knitr/downloads
忍者秘籍: https://bookdown.org/yihui/r-ninja/
rmarkdown相关包
knitr定义样式 https://yihui.name/knitr/
prettydoc 漂亮的html https://github.com/yixuan/prettydoc/
tufte 讲义风格 https://github.com/rstudio/tufte
templates模板 https://github.com/hrbrmstr/markdowntemplates
rmdformats https://github.com/juba/rmdformats
knitrBootstrap https://github.com/jimhester/knitrBootstrap
rticles杂志排版 https://github.com/rstudio/rticles
flexdashboard https://github.com/rstudio/flexdashboard
https://github.com/svmiller/svm-r-markdown-templates
表格相关
DT https://datatables.net/manual/styling/classes
kableExtra https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html
pander
knit_theme$get()# http://animation.r-forge.r-project.org/knitr/
命令行向rmd 里传递参数
R -e "thetitle='My title'; theauthor='me'; rmarkdown::render('test.rmd')"
教程
中文教程
https://zhuanlan.zhihu.com/p/24884324
https://rpubs.com/marschmi/RMarkdown
https://bookdown.org/yihui/bookdown/figures.html
http://rmarkdown.rstudio.com/lesson-7.html
http://rmarkdown.rstudio.com/markdown_document_format.html
http://rmarkdown.rstudio.com/html_document_format.html
http://rmarkdown.rstudio.com/pdf_document_format.html
http://rmarkdown.rstudio.com/rmarkdown_websites.html
YAML 设置,注意缩进
---
title: "标题"
author:"作者"
date:"`r Sys.Date()`"
output:html_document: or pdf_document or word_document
theme: cerulean #样式
highlight: zenburn
css: styles.css #自定义css
codefloding:hide(隐藏) show(显示)
toc:yes #添加目录
toc_depth: 3 #目录标题的深度
toc_float: True #目录作为侧边栏
collapsed:TRUE #仅包含H2,其它折叠,滑到标签才打开
smooth_scroll:T #平滑滚动
number_sections:yes #目录自动编号
fig_caption 控制图形是否带有标题
fig_width fig_height可以用来控制默认图形的宽度和高度(7X5使用默认情况下)
fig_retina指定为视网膜显示执行的缩放比例
fig_crop 使用pdfcrop裁剪PDF(默认情况下为true)
dev 控制用于渲染数字的图形设备(html默认为png,pdf为pdf)
df_print: paged 选项增强数据框的默认显示
mathjax: local 使用“本地”时,要将self_contained选项设置为false。
self_contained: false 如果你想保持外部文件的依赖,你可以指定self_contained: false
lib_dir: libs 合并多个外部文档共享到单个目录中
keep_md: true 您想在渲染后保留一份.md文件
includes:要在文档标题中或在文档正文之前/之后包含内容
in_header: header.html
before_body: doc_prefix.html
after_body: doc_suffix.html
template: quarterly_report.html 自定义模板 http://pandoc.org/MANUAL.html#templates
md_extensions:: -autolink_bare_uris+hard_line_breaks
选项启用或禁用缩减扩展程序(前言-为禁用并+启用该选项)
pandoc_args: [
"--title-prefix", "Foo",
"--id-prefix", "Bar"
]
---
theme主题包括:
"default","cerulean","journal","flatly","readable","spacelab","united","cosmo","lumen","paper","sandstone","simplex",和"yeti"。
传递null,可以使用css参数来添加自己的样式
highlight 语法高亮包括 :
"default","tango","pygments","kate","monochrome","espresso","zenburn","haddock",和"textmate"
## Next Steps {#nextsteps .emphasized} 自定义ID class
## Quarterly Results {.tabset .tabset-fade .tabset-pills}
.tabset 属性的标题的所有子标题出现在标签
.tabset-fade 属性导致切换时标签淡入淡出。
.tabset-pills属性导致标签的视觉外观是“药片”而不是传统的标签
knitr::kable(mtcars) #表格
knitr::include_graphics() #读取图片
df_print 表格打印参数:
default Call the print.data.frame generic method
kable Use the knitr::kable function.
tibble Use the tibble::print.tbl_df function.
paged Use the rmarkdown::print.paged_df function which creates a pageable HTML table
选项 描述
max.print 要打印的行数。
rows.print 要显示的行数。
cols.print 要显示的列数。
cols.min.print 要显示的最少列数。
pages.print 在页面导航下显示的页面数量。
paged.print 当设置为FALSE关闭分页表。
rownames.print 设置为FALSE关闭行名称时。
### 嵌入代码
1.嵌入行内如`r 1+1`
2.代码块
knitr::opts_chunk$set(echo = FALSE, fig.height = 4)
所有选项可参考: https://yihui.name/knitr/options/
eval TRUE 是否执行代码,F则原样输出源代码
echo TRUE 是否显示代码,甚至精确控制显示哪几段代码(echo取数值)
include FALSE
warning TRUE 显示警号信息,
error FALSE Whether to display errors
message TRUE Whether to display messages
tidy FALSE 代码重排
highlight TRUE 增强可读性,有无数的高亮主题可选,仅适用于LaTeX和HTML输出
results "markup" "markup", "asis", "hold", or "hide" 普通文本输出或将文本输出以原样形式输出
cache FALSE 选项cache=TRUE来启用缓存,相应的cache.path选项用来设置缓存文件的路径。
comment "##" Comment character to preface results with
out.width和out.height设置图片在输出文档中的宽高
fig.width 7 Width in inches for plots created in chunk
fig.height 7 Height in inches for plots created in chunk
fig.path 用来设置图形输出的路径
fig.keep 设置保留图形的方式
fig.show 设置图形显示的方式
[详细看](yihui.name/knitr/)
指定一组默认选项,以便在目录内的多个文档之间共享,
可以在目录中包含一个名为 _output.yaml 的文件,例如:
html_document:
self_contained: false
theme: united
highlight: textmate
HTML碎片
如果要创建HTML片段而不是完整的HTML文档,
则可以使用该html_fragment格式。例如:
---
output: html_fragment
---
## 从模板创建
rmarkdown::draft("MyJSSArticle.Rmd", template = "jss_article", package = "rticles")
### 渲染
rmarkdown::render("<file path>")
rmarkdown::render_site 功能将R Markdown文档的集合呈现为网站
rmarkdown::run("")