├── latex ├── after_body.tex ├── before_body.tex ├── preamble.tex └── template.tex ├── 08-bio-application.Rmd ├── cover.png ├── data └── data-import │ ├── example.json │ ├── mtcars.rds │ ├── mtcars.RData │ ├── mtcars.xlsx │ ├── mtcars.csv │ └── mtcars.tsv ├── docs ├── cover.png ├── fig │ ├── ch02-fun-env.png │ ├── ch01-rtools-mac.PNG │ ├── ch01-rtools-win.PNG │ ├── ch00-data-science.png │ ├── ch01-select-64-bit.PNG │ ├── ch01-download-rstudio.PNG │ ├── ch01-rstudio-overview.PNG │ ├── ch02-rstudio-env-panel.PNG │ └── ch01-set-install-path-win.PNG ├── bookdown_files │ └── figure-html │ │ ├── vector-add-1.png │ │ ├── vector-align-1.png │ │ ├── unnamed-chunk-146-1.png │ │ ├── unnamed-chunk-147-1.png │ │ ├── unnamed-chunk-148-1.png │ │ ├── unnamed-chunk-149-1.png │ │ ├── unnamed-chunk-151-1.png │ │ ├── unnamed-chunk-153-1.png │ │ ├── unnamed-chunk-158-1.png │ │ ├── unnamed-chunk-159-1.png │ │ └── vector-construction-1.png ├── libs │ └── gitbook │ │ ├── css │ │ ├── fontawesome │ │ │ └── fontawesome-webfont.ttf │ │ ├── plugin-clipboard.css │ │ ├── plugin-table.css │ │ ├── plugin-search.css │ │ ├── plugin-bookdown.css │ │ └── plugin-fontsettings.css │ │ └── js │ │ ├── plugin-clipboard.js │ │ ├── jquery.highlight.js │ │ ├── plugin-sharing.js │ │ ├── plugin-fontsettings.js │ │ ├── plugin-search.js │ │ ├── plugin-bookdown.js │ │ ├── clipboard.min.js │ │ └── lunr.js ├── css │ └── style.css ├── references.html ├── bioapp.html └── author.html ├── .gitignore ├── .Rprofile ├── fig ├── ch02-fun-env.png ├── ch01-rtools-mac.PNG ├── ch01-rtools-win.PNG ├── ch00-data-science.png ├── ch01-select-64-bit.PNG ├── ch01-download-rstudio.PNG ├── ch01-rstudio-overview.PNG ├── ch02-rstudio-env-panel.PNG └── ch01-set-install-path-win.PNG ├── _common.R ├── 06-data-model.Rmd ├── 05-data-visualization.Rmd ├── render.R ├── _bookdown.yml ├── 10-references.Rmd ├── 00-author.Rmd ├── geek-r-tutorial.Rproj ├── book.bib ├── css └── style.css ├── 07-result-report.Rmd ├── 04-data-clean.Rmd ├── README.md ├── _output.yml ├── bookdown.log ├── 09-supp.Rmd ├── index.Rmd ├── packages.bib ├── 03-data-import.Rmd ├── 01-prepare.Rmd └── bookdown.tex /latex/after_body.tex: -------------------------------------------------------------------------------- 1 | \backmatter 2 | \printindex 3 | -------------------------------------------------------------------------------- /08-bio-application.Rmd: -------------------------------------------------------------------------------- 1 | # 生物信息学应用 {#bioapp} 2 | 3 | 瞎扯几句。 4 | 5 | -------------------------------------------------------------------------------- /cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/cover.png -------------------------------------------------------------------------------- /data/data-import/example.json: -------------------------------------------------------------------------------- 1 | {"a":[1],"b":[2,3,4,5],"c":[true,false],"d":{}} 2 | -------------------------------------------------------------------------------- /docs/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/cover.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | _book 6 | _bookdown_files 7 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | source("~/.Rprofile") 2 | if (.Platform$OS.type == 'windows') Sys.setlocale(, 'Chinese') 3 | -------------------------------------------------------------------------------- /fig/ch02-fun-env.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch02-fun-env.png -------------------------------------------------------------------------------- /fig/ch01-rtools-mac.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch01-rtools-mac.PNG -------------------------------------------------------------------------------- /fig/ch01-rtools-win.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch01-rtools-win.PNG -------------------------------------------------------------------------------- /data/data-import/mtcars.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/data/data-import/mtcars.rds -------------------------------------------------------------------------------- /docs/fig/ch02-fun-env.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch02-fun-env.png -------------------------------------------------------------------------------- /fig/ch00-data-science.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch00-data-science.png -------------------------------------------------------------------------------- /fig/ch01-select-64-bit.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch01-select-64-bit.PNG -------------------------------------------------------------------------------- /data/data-import/mtcars.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/data/data-import/mtcars.RData -------------------------------------------------------------------------------- /data/data-import/mtcars.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/data/data-import/mtcars.xlsx -------------------------------------------------------------------------------- /docs/fig/ch01-rtools-mac.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch01-rtools-mac.PNG -------------------------------------------------------------------------------- /docs/fig/ch01-rtools-win.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch01-rtools-win.PNG -------------------------------------------------------------------------------- /fig/ch01-download-rstudio.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch01-download-rstudio.PNG -------------------------------------------------------------------------------- /fig/ch01-rstudio-overview.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch01-rstudio-overview.PNG -------------------------------------------------------------------------------- /docs/fig/ch00-data-science.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch00-data-science.png -------------------------------------------------------------------------------- /docs/fig/ch01-select-64-bit.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch01-select-64-bit.PNG -------------------------------------------------------------------------------- /fig/ch02-rstudio-env-panel.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch02-rstudio-env-panel.PNG -------------------------------------------------------------------------------- /docs/fig/ch01-download-rstudio.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch01-download-rstudio.PNG -------------------------------------------------------------------------------- /docs/fig/ch01-rstudio-overview.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch01-rstudio-overview.PNG -------------------------------------------------------------------------------- /fig/ch01-set-install-path-win.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/fig/ch01-set-install-path-win.PNG -------------------------------------------------------------------------------- /docs/fig/ch02-rstudio-env-panel.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch02-rstudio-env-panel.PNG -------------------------------------------------------------------------------- /docs/fig/ch01-set-install-path-win.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/fig/ch01-set-install-path-win.PNG -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/vector-add-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/vector-add-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/vector-align-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/vector-align-1.png -------------------------------------------------------------------------------- /_common.R: -------------------------------------------------------------------------------- 1 | knitr::opts_chunk$set( 2 | fig.align = 'center', 3 | fig.width = 4, 4 | fig.height = 4, 5 | collapse = TRUE, 6 | comment = "#>", 7 | message = FALSE 8 | ) -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-146-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-146-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-147-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-147-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-148-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-148-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-149-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-149-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-151-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-151-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-153-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-153-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-158-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-158-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/unnamed-chunk-159-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/unnamed-chunk-159-1.png -------------------------------------------------------------------------------- /docs/bookdown_files/figure-html/vector-construction-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/bookdown_files/figure-html/vector-construction-1.png -------------------------------------------------------------------------------- /docs/libs/gitbook/css/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShixiangWang/geek-r-tutorial/HEAD/docs/libs/gitbook/css/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /06-data-model.Rmd: -------------------------------------------------------------------------------- 1 | # 统计建模 {#model} 2 | 3 | 瞎扯几句。 4 | 5 | ## 常见问题与方案 {-} 6 | 7 | 除了本节目前罗列的问题,读者在学习本章内容时遇到的其他问题都可以通过 [GitHub Issue](https://github.com/ShixiangWang/geek-r-tutorial/issues) 提出和进行讨论。如果读者提出的是通性问题,将增补到该节。 -------------------------------------------------------------------------------- /latex/before_body.tex: -------------------------------------------------------------------------------- 1 | 2 | \thispagestyle{empty} 3 | 4 | \begin{center} 5 | 献给…… 6 | 7 | 呃,爱谁谁吧 8 | \end{center} 9 | 10 | \setlength{\abovedisplayskip}{-5pt} 11 | \setlength{\abovedisplayshortskip}{-5pt} 12 | -------------------------------------------------------------------------------- /05-data-visualization.Rmd: -------------------------------------------------------------------------------- 1 | # 数据可视化 {#visualization} 2 | 3 | 瞎扯几句。 4 | 5 | ## 常见问题与方案 {-} 6 | 7 | 除了本节目前罗列的问题,读者在学习本章内容时遇到的其他问题都可以通过 [GitHub Issue](https://github.com/ShixiangWang/geek-r-tutorial/issues) 提出和进行讨论。如果读者提出的是通性问题,将增补到该节。 -------------------------------------------------------------------------------- /render.R: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env Rscript 2 | # 确保自己在book目录下 3 | 4 | bookdown::render_book("index.Rmd") 5 | #bookdown::render_book("index.Rmd", output_format = "all") 6 | unlink("docs/*", recursive = TRUE, force = TRUE) 7 | system("cp -rf _book/* docs") -------------------------------------------------------------------------------- /_bookdown.yml: -------------------------------------------------------------------------------- 1 | book_filename: bookdown 2 | clean: [packages.bib, bookdown.bbl] 3 | language: 4 | label: 5 | fig: "图 " 6 | tab: "表 " 7 | ui: 8 | edit: "编辑" 9 | chapter_name: ["第 ", " 章"] 10 | 11 | before_chapter_script: "_common.R" -------------------------------------------------------------------------------- /10-references.Rmd: -------------------------------------------------------------------------------- 1 | `r if (knitr:::is_html_output()) '# 参考文献 {#references .unnumbered}'` 2 | 3 | ```{r include=FALSE} 4 | # 自动生成 R 包的参考文献 5 | knitr::write_bib(c( 6 | .packages(), 'bookdown', 'knitr', 'rmarkdown' 7 | ), 'packages.bib') 8 | ``` 9 | 10 | -------------------------------------------------------------------------------- /00-author.Rmd: -------------------------------------------------------------------------------- 1 | # 作者简介 {#author .unnumbered} 2 | 3 | [王诗翔](https://shixiangwang.github.io/home/cn/),生信技能树成员,R 语言爱好者。对编程、数据分析都有比较浓厚的兴趣,喜欢开源与开放的科学。长期在简书发文,连载文集[《极客RrR<<-数据分析之道》](https://www.jianshu.com/nb/22007361),并运营微信公众号[《优雅R》](https://shixiangwang.github.io/home/logo/qrcode.jpg)用于推送数据分析相关知识。 4 | -------------------------------------------------------------------------------- /geek-r-tutorial.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Website 16 | -------------------------------------------------------------------------------- /book.bib: -------------------------------------------------------------------------------- 1 | @Book{xie2015, 2 | title = {Dynamic Documents with {R} and knitr}, 3 | author = {Yihui Xie}, 4 | publisher = {Chapman and Hall/CRC}, 5 | address = {Boca Raton, Florida}, 6 | year = {2015}, 7 | edition = {2nd}, 8 | note = {ISBN 978-1498716963}, 9 | url = {http://yihui.name/knitr/}, 10 | } 11 | -------------------------------------------------------------------------------- /docs/libs/gitbook/css/plugin-clipboard.css: -------------------------------------------------------------------------------- 1 | div.sourceCode { 2 | position: relative; 3 | } 4 | 5 | .copy-to-clipboard-button { 6 | position: absolute; 7 | right: 0; 8 | top: 0; 9 | visibility: hidden; 10 | } 11 | 12 | .copy-to-clipboard-button:focus { 13 | outline: 0; 14 | } 15 | 16 | div.sourceCode:hover > .copy-to-clipboard-button { 17 | visibility: visible; 18 | } 19 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | p.caption { 2 | color: #777; 3 | margin-top: 10px; 4 | } 5 | p code { 6 | white-space: inherit; 7 | } 8 | pre { 9 | word-break: normal; 10 | word-wrap: normal; 11 | } 12 | pre code { 13 | white-space: inherit; 14 | } 15 | p.flushright { 16 | text-align: right; 17 | } 18 | blockquote > p:last-child { 19 | text-align: right; 20 | } 21 | blockquote > p:first-child { 22 | text-align: inherit; 23 | } 24 | -------------------------------------------------------------------------------- /docs/css/style.css: -------------------------------------------------------------------------------- 1 | p.caption { 2 | color: #777; 3 | margin-top: 10px; 4 | } 5 | p code { 6 | white-space: inherit; 7 | } 8 | pre { 9 | word-break: normal; 10 | word-wrap: normal; 11 | } 12 | pre code { 13 | white-space: inherit; 14 | } 15 | p.flushright { 16 | text-align: right; 17 | } 18 | blockquote > p:last-child { 19 | text-align: right; 20 | } 21 | blockquote > p:first-child { 22 | text-align: inherit; 23 | } 24 | -------------------------------------------------------------------------------- /07-result-report.Rmd: -------------------------------------------------------------------------------- 1 | # 结果展示 {#report} 2 | 3 | 瞎扯几句。 4 | 5 | ## 图形 6 | 7 | ## 表格 8 | 9 | ### Excel 10 | 11 | https://github.com/ropensci/writexl 12 | 13 | https://github.com/ycphs/openxlsx 14 | 15 | ## RMarkdown 16 | 17 | ## Shiny 18 | 19 | ## 常见问题与方案 20 | 21 | 除了本节目前罗列的问题,读者在学习本章内容时遇到的其他问题都可以通过 [GitHub Issue](https://github.com/ShixiangWang/geek-r-tutorial/issues) 提出和进行讨论。如果读者提出的是通性问题,将增补到该节。 22 | 23 | ### export 包:集才华与一身 24 | 25 | https://github.com/tomwenseleers/export -------------------------------------------------------------------------------- /docs/libs/gitbook/css/plugin-table.css: -------------------------------------------------------------------------------- 1 | .book .book-body .page-wrapper .page-inner section.normal table{display:table;width:100%;border-collapse:collapse;border-spacing:0;overflow:auto}.book .book-body .page-wrapper .page-inner section.normal table td,.book .book-body .page-wrapper .page-inner section.normal table th{padding:6px 13px;border:1px solid #ddd}.book .book-body .page-wrapper .page-inner section.normal table tr{background-color:#fff;border-top:1px solid #ccc}.book .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n){background-color:#f8f8f8}.book .book-body .page-wrapper .page-inner section.normal table th{font-weight:700} 2 | -------------------------------------------------------------------------------- /04-data-clean.Rmd: -------------------------------------------------------------------------------- 1 | # 数据清洗 {#clean} 2 | 3 | 数据的清洗是数据分析最核心的技能,读者需要长时间的学习和实战方能掌握。复杂的操作往往由基础的操作堆砌组合而成,本章的重点就是帮助读者快速学习和掌握数据清理最核心的操作单元。我将逐步讲解如何处理向量、单个数据集、两个数据集和多个数据集最基础且实用的数据操作方式,其他相关的内容将放到本章**【常见问题与方案】**一节作为补充介绍。。 4 | 5 | R 丰富的特性支持以多种方式完成相同的操作,对于大部分的操作,我将介绍 3 种不同的解决方案: 6 | 7 | 1. tidyverse 方式。 8 | 2. R 内置操作方式。 9 | 3. data.table 方式。 10 | 11 | 读者可以根据自己的需求选择性的学习,也可以进行全面的了解和学习。**tidyverse** 方式目前已经成为 R 处理数据的主流方案,我推荐读者重点掌握。注意,读者切勿画地为牢,数据分析重在**解决**,而不在于**手段**,实际处理数据时应当灵活使用可以运用的工具方法,上述 3 种方式有时也可以有机地组合运用,并非相互排斥。 12 | 13 | ## 向量 14 | 15 | ## 单个数据集 16 | 17 | ### 选择列 18 | 19 | ### 过滤行 20 | 21 | ### 新增列 22 | 23 | ### 聚合运算 24 | 25 | ### 分组计算 26 | 27 | ### 缺失值填充 28 | 29 | ## 两个数据集 30 | 31 | ## 多个数据集 32 | 33 | ## 常见问题与方案 34 | 35 | 除了本节目前罗列的问题,读者在学习本章内容时遇到的其他问题都可以通过 [GitHub Issue](https://github.com/ShixiangWang/geek-r-tutorial/issues) 提出和进行讨论。如果读者提出的是通性问题,将增补到该节。 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 极客R:数据分析之道 2 | 3 | [![HitCount](http://hits.dwyl.com/ShixiangWang/geek-r-tutorial.svg)](http://hits.dwyl.com/ShixiangWang/geek-r-tutorial) 4 | 5 | [GitHub 仓库](https://github.com/ShixiangWang/geek-r-tutorial) | [Gitee 仓库](https://gitee.com/ShixiangWang/geek-r-tutorial) 6 | 7 | 这是生信技能树的 R 入门教程,由 [**bookdown**](https://bookdown.org/yihui/bookdown) 驱动编写而成。 8 | 9 | - 阅读请点击:,Gitee 有一个镜像 ,对国内读者更加友好。 10 | - 问题和交流请通过 [issue](https://github.com/ShixiangWang/geek-r-tutorial/issues) 进行。 11 | 12 | # 许可 13 | 14 | 本网站(永久)免费阅读,以 [CC 署名-非商业性使用-禁止演绎 4.0 国际协议](https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh)发行。 15 | 16 | Copyright © 2020 王诗翔 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/libs/gitbook/css/plugin-search.css: -------------------------------------------------------------------------------- 1 | .book .book-summary .book-search { 2 | padding: 6px; 3 | background: transparent; 4 | position: absolute; 5 | top: -50px; 6 | left: 0px; 7 | right: 0px; 8 | transition: top 0.5s ease; 9 | } 10 | .book .book-summary .book-search input, 11 | .book .book-summary .book-search input:focus, 12 | .book .book-summary .book-search input:hover { 13 | width: 100%; 14 | background: transparent; 15 | border: 1px solid #ccc; 16 | box-shadow: none; 17 | outline: none; 18 | line-height: 22px; 19 | padding: 7px 4px; 20 | color: inherit; 21 | box-sizing: border-box; 22 | } 23 | .book.with-search .book-summary .book-search { 24 | top: 0px; 25 | } 26 | .book.with-search .book-summary ul.summary { 27 | top: 50px; 28 | } 29 | .with-search .summary li[data-level] a[href*=".html#"] { 30 | display: none; 31 | } 32 | -------------------------------------------------------------------------------- /_output.yml: -------------------------------------------------------------------------------- 1 | bookdown::gitbook: 2 | css: css/style.css 3 | config: 4 | toc: 5 | collapse: section 6 | before: | 7 |
  • 数据分析之道
  • 8 | # download: [pdf, epub] 9 | edit: https://github.com/ShixiangWang/geek-r-tutorial/edit/master/%s 10 | sharing: 11 | github: yes 12 | twitter: yes 13 | bookdown::pdf_book: 14 | includes: 15 | in_header: latex/preamble.tex 16 | before_body: latex/before_body.tex 17 | after_body: latex/after_body.tex 18 | keep_tex: yes 19 | dev: "cairo_pdf" 20 | latex_engine: xelatex 21 | citation_package: natbib 22 | template: latex/template.tex 23 | pandoc_args: "--top-level-division=chapter" 24 | toc_depth: 3 25 | toc_unnumbered: no 26 | toc_appendix: yes 27 | quote_footer: ["\\begin{flushright}", "\\end{flushright}"] 28 | bookdown::epub_book: 29 | stylesheet: css/style.css 30 | -------------------------------------------------------------------------------- /docs/libs/gitbook/js/plugin-clipboard.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "jQuery"], function(gitbook, $) { 2 | 3 | var copyButton = ''; 4 | var clipboard; 5 | 6 | gitbook.events.bind("page.change", function() { 7 | 8 | if (!ClipboardJS.isSupported()) return; 9 | 10 | // the page.change event is thrown twice: before and after the page changes 11 | if (clipboard) { 12 | // clipboard is already defined 13 | // we can deduct that we are before page changes 14 | clipboard.destroy(); // destroy the previous events listeners 15 | clipboard = undefined; // reset the clipboard object 16 | return; 17 | } 18 | 19 | $(copyButton).prependTo("div.sourceCode"); 20 | 21 | clipboard = new ClipboardJS(".copy-to-clipboard-button", { 22 | text: function(trigger) { 23 | return trigger.parentNode.textContent; 24 | } 25 | }); 26 | 27 | }); 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /bookdown.log: -------------------------------------------------------------------------------- 1 | This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019/W32TeX) (preloaded format=xelatex 2019.12.14) 6 MAR 2020 17:56 2 | entering extended mode 3 | restricted \write18 enabled. 4 | %&-line parsing enabled. 5 | **bookdown.tex 6 | (./bookdown.tex 7 | LaTeX2e <2019-10-01> patch level 3 8 | 9 | ! LaTeX Error: File `ctexbook.cls' not found. 10 | 11 | Type X to quit or to proceed, 12 | or enter new name. (Default extension: cls) 13 | 14 | Enter file name: 15 | ! Emergency stop. 16 | 17 | 18 | l.2 \usepackage 19 | {lmodern}^^M 20 | Here is how much of TeX's memory you used: 21 | 10 strings out of 494458 22 | 119 string characters out of 6171841 23 | 58050 words of memory out of 5000000 24 | 4470 multiletter control sequences out of 15000+600000 25 | 3640 words of font info for 14 fonts, out of 8000000 for 9000 26 | 14 hyphenation exceptions out of 8191 27 | 14i,0n,8p,53b,10s stack positions out of 5000i,500n,10000p,200000b,80000s 28 | 29 | No pages of output. 30 | 31 | 32 | ! kpathsea: Running mktexfmt xelatex.fmt 33 | 34 | ! The command name is C:\Users\Shixiang\AppData\Roaming\TinyTeX\bin\win32\mktexfmt 35 | -------------------------------------------------------------------------------- /data/data-import/mtcars.csv: -------------------------------------------------------------------------------- 1 | mpg,cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb 2 | 21,6,160,110,3.9,2.62,16.46,0,1,4,4 3 | 21,6,160,110,3.9,2.875,17.02,0,1,4,4 4 | 22.8,4,108,93,3.85,2.32,18.61,1,1,4,1 5 | 21.4,6,258,110,3.08,3.215,19.44,1,0,3,1 6 | 18.7,8,360,175,3.15,3.44,17.02,0,0,3,2 7 | 18.1,6,225,105,2.76,3.46,20.22,1,0,3,1 8 | 14.3,8,360,245,3.21,3.57,15.84,0,0,3,4 9 | 24.4,4,146.7,62,3.69,3.19,20,1,0,4,2 10 | 22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2 11 | 19.2,6,167.6,123,3.92,3.44,18.3,1,0,4,4 12 | 17.8,6,167.6,123,3.92,3.44,18.9,1,0,4,4 13 | 16.4,8,275.8,180,3.07,4.07,17.4,0,0,3,3 14 | 17.3,8,275.8,180,3.07,3.73,17.6,0,0,3,3 15 | 15.2,8,275.8,180,3.07,3.78,18,0,0,3,3 16 | 10.4,8,472,205,2.93,5.25,17.98,0,0,3,4 17 | 10.4,8,460,215,3,5.424,17.82,0,0,3,4 18 | 14.7,8,440,230,3.23,5.345,17.42,0,0,3,4 19 | 32.4,4,78.7,66,4.08,2.2,19.47,1,1,4,1 20 | 30.4,4,75.7,52,4.93,1.615,18.52,1,1,4,2 21 | 33.9,4,71.1,65,4.22,1.835,19.9,1,1,4,1 22 | 21.5,4,120.1,97,3.7,2.465,20.01,1,0,3,1 23 | 15.5,8,318,150,2.76,3.52,16.87,0,0,3,2 24 | 15.2,8,304,150,3.15,3.435,17.3,0,0,3,2 25 | 13.3,8,350,245,3.73,3.84,15.41,0,0,3,4 26 | 19.2,8,400,175,3.08,3.845,17.05,0,0,3,2 27 | 27.3,4,79,66,4.08,1.935,18.9,1,1,4,1 28 | 26,4,120.3,91,4.43,2.14,16.7,0,1,5,2 29 | 30.4,4,95.1,113,3.77,1.513,16.9,1,1,5,2 30 | 15.8,8,351,264,4.22,3.17,14.5,0,1,5,4 31 | 19.7,6,145,175,3.62,2.77,15.5,0,1,5,6 32 | 15,8,301,335,3.54,3.57,14.6,0,1,5,8 33 | 21.4,4,121,109,4.11,2.78,18.6,1,1,4,2 34 | -------------------------------------------------------------------------------- /data/data-import/mtcars.tsv: -------------------------------------------------------------------------------- 1 | mpg cyl disp hp drat wt qsec vs am gear carb 2 | 21 6 160 110 3.9 2.62 16.46 0 1 4 4 3 | 21 6 160 110 3.9 2.875 17.02 0 1 4 4 4 | 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1 5 | 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 6 | 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2 7 | 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1 8 | 14.3 8 360 245 3.21 3.57 15.84 0 0 3 4 9 | 24.4 4 146.7 62 3.69 3.19 20 1 0 4 2 10 | 22.8 4 140.8 95 3.92 3.15 22.9 1 0 4 2 11 | 19.2 6 167.6 123 3.92 3.44 18.3 1 0 4 4 12 | 17.8 6 167.6 123 3.92 3.44 18.9 1 0 4 4 13 | 16.4 8 275.8 180 3.07 4.07 17.4 0 0 3 3 14 | 17.3 8 275.8 180 3.07 3.73 17.6 0 0 3 3 15 | 15.2 8 275.8 180 3.07 3.78 18 0 0 3 3 16 | 10.4 8 472 205 2.93 5.25 17.98 0 0 3 4 17 | 10.4 8 460 215 3 5.424 17.82 0 0 3 4 18 | 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4 19 | 32.4 4 78.7 66 4.08 2.2 19.47 1 1 4 1 20 | 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 21 | 33.9 4 71.1 65 4.22 1.835 19.9 1 1 4 1 22 | 21.5 4 120.1 97 3.7 2.465 20.01 1 0 3 1 23 | 15.5 8 318 150 2.76 3.52 16.87 0 0 3 2 24 | 15.2 8 304 150 3.15 3.435 17.3 0 0 3 2 25 | 13.3 8 350 245 3.73 3.84 15.41 0 0 3 4 26 | 19.2 8 400 175 3.08 3.845 17.05 0 0 3 2 27 | 27.3 4 79 66 4.08 1.935 18.9 1 1 4 1 28 | 26 4 120.3 91 4.43 2.14 16.7 0 1 5 2 29 | 30.4 4 95.1 113 3.77 1.513 16.9 1 1 5 2 30 | 15.8 8 351 264 4.22 3.17 14.5 0 1 5 4 31 | 19.7 6 145 175 3.62 2.77 15.5 0 1 5 6 32 | 15 8 301 335 3.54 3.57 14.6 0 1 5 8 33 | 21.4 4 121 109 4.11 2.78 18.6 1 1 4 2 34 | -------------------------------------------------------------------------------- /latex/preamble.tex: -------------------------------------------------------------------------------- 1 | \usepackage{booktabs} 2 | \usepackage{longtable} 3 | 4 | \usepackage{framed,color} 5 | \definecolor{shadecolor}{RGB}{248,248,248} 6 | 7 | \renewcommand{\textfraction}{0.05} 8 | \renewcommand{\topfraction}{0.8} 9 | \renewcommand{\bottomfraction}{0.8} 10 | \renewcommand{\floatpagefraction}{0.75} 11 | 12 | \let\oldhref\href 13 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 14 | 15 | \makeatletter 16 | \newenvironment{kframe}{% 17 | \medskip{} 18 | \setlength{\fboxsep}{.8em} 19 | \def\at@end@of@kframe{}% 20 | \ifinner\ifhmode% 21 | \def\at@end@of@kframe{\end{minipage}}% 22 | \begin{minipage}{\columnwidth}% 23 | \fi\fi% 24 | \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep 25 | \colorbox{shadecolor}{##1}\hskip-\fboxsep 26 | % There is no \\@totalrightmargin, so: 27 | \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}% 28 | \MakeFramed {\advance\hsize-\width 29 | \@totalleftmargin\z@ \linewidth\hsize 30 | \@setminipage}}% 31 | {\par\unskip\endMakeFramed% 32 | \at@end@of@kframe} 33 | \makeatother 34 | 35 | \makeatletter 36 | \@ifundefined{Shaded}{ 37 | }{\renewenvironment{Shaded}{\begin{kframe}}{\end{kframe}}} 38 | \@ifpackageloaded{fancyvrb}{% 39 | % https://github.com/CTeX-org/ctex-kit/issues/331 40 | \RecustomVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},formatcom=\xeCJKVerbAddon}% 41 | }{} 42 | \makeatother 43 | 44 | \usepackage{makeidx} 45 | \makeindex 46 | 47 | \urlstyle{tt} 48 | 49 | \usepackage{amsthm} 50 | \makeatletter 51 | \def\thm@space@setup{% 52 | \thm@preskip=8pt plus 2pt minus 4pt 53 | \thm@postskip=\thm@preskip 54 | } 55 | \makeatother 56 | 57 | \frontmatter 58 | -------------------------------------------------------------------------------- /09-supp.Rmd: -------------------------------------------------------------------------------- 1 | \cleardoublepage 2 | 3 | # (APPENDIX) 附录 {-} 4 | 5 | # 速查表 {#search-table} 6 | 7 | ## 数值计算函数 8 | 9 | ## 模型符号与函数 10 | 11 | ## 统计分析与检验 12 | 13 | # 拓展阅读 {#expand-reading} 14 | 15 | 呐,到这里本教程的内容差不多写完了。下面是一些推荐的学习资料,希望能够帮到想要进一步学习的读者。 16 | 大部分的资料是英文的,大家一定要根据自己的实际情况选择合适的资料,建立切实可行的学习计划。 17 | 18 | ## 生信技能树语雀知识库 19 | 20 | - [生物信息入门需要了解的十个专题](https://www.yuque.com/biotrainee/org3dm) 21 | - [生物统计从理论到实践](https://www.yuque.com/biotrainee/biostat) 22 | - [肿瘤外显子数据分析指南](https://www.yuque.com/biotrainee/wes) 23 | - [TCGA数据分析指南](https://www.yuque.com/biotrainee/tcga) 24 | - [生信菜鸟团-每周文献分享](https://www.yuque.com/biotrainee/weeklypaper) 25 | 26 | ## 图书 27 | 28 | ### 问题与方案 29 | 30 | - [Cookbook for R 中文版](https://openbiox.github.io/Cookbook-for-R-Chinese/) 31 | 32 | ### 统计建模 33 | 34 | - [Data Science Live Book](https://livebook.datascienceheroes.com/) 35 | - [Statistical Inference via Data Science - A ModernDive into R and the tidyverse](https://moderndive.com/) 36 | 37 | ### 核心集合 38 | 39 | - [R for Data Science](https://r4ds.had.co.nz/) 40 | - [Anvanced R](https://adv-r.hadley.nz/) 41 | - [R Packages](https://r-pkgs.org/) 42 | 43 | ### 生物信息学 44 | 45 | - [生物信息学生 R 入门教程](http://qiubio.com/new/book/) 46 | 47 | ### R 48 | 49 | - [R 语言教程](http://www.math.pku.edu.cn/teachers/lidf/docs/Rbook/html/_Rbook/index.html) 50 | - [统计计算](http://www.math.pku.edu.cn/teachers/lidf/docs/statcomp/html/_statcompbook/index.html) 51 | 52 | ## 视频 53 | 54 | - [生信技能树 B 站视频集](https://space.bilibili.com/338686099) 55 | 56 | ## 公众号 57 | 58 | - 生信菜鸟团 59 | - 生信技能树 60 | - biobabble 61 | - 优雅R 62 | 63 | ## 其他资料 64 | 65 | - [Jimmy - GEO 流程](https://github.com/jmzeng1314/GEO) 66 | - [Jimmy - NGS 流程](https://github.com/jmzeng1314/NGS-pipeline) -------------------------------------------------------------------------------- /docs/libs/gitbook/css/plugin-bookdown.css: -------------------------------------------------------------------------------- 1 | .book .book-header h1 { 2 | padding-left: 20px; 3 | padding-right: 20px; 4 | } 5 | .book .book-header.fixed { 6 | position: fixed; 7 | right: 0; 8 | top: 0; 9 | left: 0; 10 | border-bottom: 1px solid rgba(0,0,0,.07); 11 | } 12 | span.search-highlight { 13 | background-color: #ffff88; 14 | } 15 | @media (min-width: 600px) { 16 | .book.with-summary .book-header.fixed { 17 | left: 300px; 18 | } 19 | } 20 | @media (max-width: 1240px) { 21 | .book .book-body.fixed { 22 | top: 50px; 23 | } 24 | .book .book-body.fixed .body-inner { 25 | top: auto; 26 | } 27 | } 28 | @media (max-width: 600px) { 29 | .book.with-summary .book-header.fixed { 30 | left: calc(100% - 60px); 31 | min-width: 300px; 32 | } 33 | .book.with-summary .book-body { 34 | transform: none; 35 | left: calc(100% - 60px); 36 | min-width: 300px; 37 | } 38 | .book .book-body.fixed { 39 | top: 0; 40 | } 41 | } 42 | 43 | .book .book-body.fixed .body-inner { 44 | top: 50px; 45 | } 46 | .book .book-body .page-wrapper .page-inner section.normal sub, .book .book-body .page-wrapper .page-inner section.normal sup { 47 | font-size: 85%; 48 | } 49 | 50 | @media print { 51 | .book .book-summary, .book .book-body .book-header, .fa { 52 | display: none !important; 53 | } 54 | .book .book-body.fixed { 55 | left: 0px; 56 | } 57 | .book .book-body,.book .book-body .body-inner, .book.with-summary { 58 | overflow: visible !important; 59 | } 60 | } 61 | .kable_wrapper { 62 | border-spacing: 20px 0; 63 | border-collapse: separate; 64 | border: none; 65 | margin: auto; 66 | } 67 | .kable_wrapper > tbody > tr > td { 68 | vertical-align: top; 69 | } 70 | .book .book-body .page-wrapper .page-inner section.normal table tr.header { 71 | border-top-width: 2px; 72 | } 73 | .book .book-body .page-wrapper .page-inner section.normal table tr:last-child td { 74 | border-bottom-width: 2px; 75 | } 76 | .book .book-body .page-wrapper .page-inner section.normal table td, .book .book-body .page-wrapper .page-inner section.normal table th { 77 | border-left: none; 78 | border-right: none; 79 | } 80 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr, .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr > td { 81 | border-top: none; 82 | } 83 | .book .book-body .page-wrapper .page-inner section.normal table.kable_wrapper > tbody > tr:last-child > td { 84 | border-bottom: none; 85 | } 86 | 87 | div.theorem, div.lemma, div.corollary, div.proposition, div.conjecture { 88 | font-style: italic; 89 | } 90 | span.theorem, span.lemma, span.corollary, span.proposition, span.conjecture { 91 | font-style: normal; 92 | } 93 | div.proof:after { 94 | content: "\25a2"; 95 | float: right; 96 | } 97 | .header-section-number { 98 | padding-right: .5em; 99 | } 100 | -------------------------------------------------------------------------------- /index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "极客R:数据分析之道" 3 | author: "王诗翔, 生信技能树" 4 | date: "上次修改 `r Sys.Date()`" 5 | documentclass: ctexbook 6 | bibliography: [book.bib, packages.bib] 7 | biblio-style: apalike 8 | link-citations: yes 9 | colorlinks: yes 10 | lot: yes 11 | lof: yes 12 | geometry: [b5paper, tmargin=2.5cm, bmargin=2.5cm, lmargin=3.5cm, rmargin=2.5cm] 13 | cover-image: cover.png 14 | site: bookdown::bookdown_site 15 | description: "一本极简 R 入门图书" 16 | github-repo: ShixiangWang/geek-r-tutorial 17 | --- 18 | 19 | ```{r setup, include=FALSE} 20 | options( 21 | htmltools.dir.version = FALSE, formatR.indent = 2, width = 55, digits = 4 22 | ) 23 | 24 | # 填上你需要用到的包,如 c('ggplot2', 'dplyr') 25 | lapply(c("tidyverse"), function(pkg) { 26 | if (system.file(package = pkg) == '') install.packages(pkg) 27 | }) 28 | ``` 29 | 30 | # 前言 {-} 31 | 32 | Cover image 33 | 34 | 这是一本 R 语言入门的教程书。它旨在为生物信息学相关方向的研究人员(包括学生)以及相关从业者提供 R 语言基础知识的学习指导。当然,由于本书内容的普适性,我相信对数据科学感兴趣的读者都能够从阅读中受益。如果读者已经掌握了一些 R 的编程知识,可以翻看目录挑选感兴趣的内容阅读;如果读者已经掌握的 R 编程基础知识,我推荐翻看本书的附录部分查找感兴趣的内容进一步深入学习。 35 | 36 | R 语言与知名的 C、Python 这类通用编程语言相比,它是一门领域特定语言(domain-specific language、DSL),专注于数据科学领域。由于 Python 的普及以及它在商业、科研分析中的流行,R 语言常常被用来与 Python 作比较。我在此无意做这样的比较,就我的个人使用经验来看,两者都有其独特和独到之处。作为一名数据科学家,我们常常需要掌握多门编程语言作为工具进行工作,其中主要包括 R、Python 和 Shell。R 和 Python 都是作为主要的数据探索、分析和可视化工具,读者任选其一熟练掌握即可。初学者同时学习 R 和 Python 是不可取,因为不同的编程语言都有相似的数据结构和运算控制逻辑,所以深度掌握一门语言能够更好地工作和更快地学习其他编程语言。另外,初学者往往困惑于 R 和 Python 两种语言中哪种更值得学习。就我的个人观点看,对于生物信息学方向的**大部分读者**,R 是更好的选择,有以下一些理由: 37 | 38 | - R 语言对于没有编程经验的读者更加友好,内置向量化运算机制和默认统计分析包可以快速开始分析和获取结果。 39 | - 由于 [Bioconductor](https://www.bioconductor.org/) 项目库和 [CRAN](https://cran.r-project.org/) 库中保存了上千个生物信息学软件包,涉及生物信息学领域的各个方面,读者在实际的研究工作中很难完全离开 R 语言环境。 40 | - [tidyverse 系列工具包](https://github.com/tidyverse/)的强力驱动让 R 在数据分析各个方面工作都非常强力。 41 | 42 | ## 内容简介 {-} 43 | 44 | 当前已经有不少 R 语言和数据分析相关的教程和书籍,本书无力像它们一样详尽地介绍 R 众多方面的内容,而是聚焦于指导读者学习和理解数据分析的核心要点,并能快速应用到自己实际的工作中。本书的创作哲学是结合必备基础知识的简要介绍与实际问题的讨论与方案。本书的核心内容包括 R 的基础语法和一系列数据分析编程知识,后者将根据 Hadley 在《R for Data Science》提供的数据分析流程概览图 \@ref(fig:r4ds-overview) 中指出的核心要点分别按章节进行介绍。最后,我们将通过一些 R 包学习 R 在生物信息学方向的应用。 45 | 46 | ```{r r4ds-overview, fig.align="center", echo=FALSE, fig.cap="数据分析概览 (图源:R for Data Science 第 1 章)"} 47 | knitr::include_graphics("fig/ch00-data-science.png") 48 | ``` 49 | 50 | 本书的章节概要如下: 51 | 52 | - 第 \@ref(prepare) 章介绍 R 与相应编程环境的安装和使用。 53 | - 第 \@ref(base) 章介绍 R 基础编程语法,包括数据结构、控制流程等。 54 | - 第 \@ref(import) 章介绍如何使用 R 导入常见的数据文件格式。 55 | - 第 \@ref(clean) 章介绍数据清洗操作在 R 中的实现。 56 | - 第 \@ref(visualization) 章介绍数据可视化。 57 | - 第 \@ref(model) 章介绍 R 在统计建模方面的和实践。 58 | - 第 \@ref(report) 章介绍 R 怎样导出结果和生成分析报告。 59 | - 第 \@ref(bioapp) 章通过一些包的使用示例介绍 R 在生物信息学方向的应用。 60 | 61 | ## 许可 {-} 62 | 63 | 本网站(永久)免费阅读,以 [CC 署名-非商业性使用-禁止演绎 4.0 国际协议](https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh)发行。 64 | 65 | Copyright © 2020 王诗翔 66 | 67 | 68 | 69 | ## 建议与反馈 {-} 70 | 71 | 这是我第一次编写比较系统的 R 语言教程,由于个人能力有限,难免存在错误和不当,恳请读者批评指正。**目前我在业余时间对本书内容进行积极的开发,如果读者有任何建议,欢迎到 [GitHub 仓库 Issue](https://github.com/ShixiangWang/geek-r-tutorial/issues) 中进行讨论**。 72 | 73 | ## 致谢 {-} 74 | 75 | 非常感谢谁谁以及谁谁对我的帮助。 76 | 77 | ```{block2, type='flushright', html.tag='p'} 78 | 王诗翔 79 | 于 上海 80 | ``` 81 | 82 | -------------------------------------------------------------------------------- /docs/libs/gitbook/js/jquery.highlight.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["jQuery"], function(jQuery) { 2 | 3 | /* 4 | * jQuery Highlight plugin 5 | * 6 | * Based on highlight v3 by Johann Burkard 7 | * http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html 8 | * 9 | * Code a little bit refactored and cleaned (in my humble opinion). 10 | * Most important changes: 11 | * - has an option to highlight only entire words (wordsOnly - false by default), 12 | * - has an option to be case sensitive (caseSensitive - false by default) 13 | * - highlight element tag and class names can be specified in options 14 | * 15 | * Copyright (c) 2009 Bartek Szopka 16 | * 17 | * Licensed under MIT license. 18 | * 19 | */ 20 | 21 | jQuery.extend({ 22 | highlight: function (node, re, nodeName, className) { 23 | if (node.nodeType === 3) { 24 | var match = node.data.match(re); 25 | if (match) { 26 | var highlight = document.createElement(nodeName || 'span'); 27 | highlight.className = className || 'highlight'; 28 | var wordNode = node.splitText(match.index); 29 | wordNode.splitText(match[0].length); 30 | var wordClone = wordNode.cloneNode(true); 31 | highlight.appendChild(wordClone); 32 | wordNode.parentNode.replaceChild(highlight, wordNode); 33 | return 1; //skip added node in parent 34 | } 35 | } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children 36 | !/(script|style)/i.test(node.tagName) && // ignore script and style nodes 37 | !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted 38 | for (var i = 0; i < node.childNodes.length; i++) { 39 | i += jQuery.highlight(node.childNodes[i], re, nodeName, className); 40 | } 41 | } 42 | return 0; 43 | } 44 | }); 45 | 46 | jQuery.fn.unhighlight = function (options) { 47 | var settings = { className: 'highlight', element: 'span' }; 48 | jQuery.extend(settings, options); 49 | 50 | return this.find(settings.element + "." + settings.className).each(function () { 51 | var parent = this.parentNode; 52 | parent.replaceChild(this.firstChild, this); 53 | parent.normalize(); 54 | }).end(); 55 | }; 56 | 57 | jQuery.fn.highlight = function (words, options) { 58 | var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false }; 59 | jQuery.extend(settings, options); 60 | 61 | if (words.constructor === String) { 62 | words = [words]; 63 | // also match 'foo-bar' if search for 'foo bar' 64 | if (/\s/.test(words[0])) words.push(words[0].replace(/\s+/, '-')); 65 | } 66 | words = jQuery.grep(words, function(word, i){ 67 | return word !== ''; 68 | }); 69 | words = jQuery.map(words, function(word, i) { 70 | return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 71 | }); 72 | if (words.length === 0) { return this; } 73 | 74 | var flag = settings.caseSensitive ? "" : "i"; 75 | var pattern = "(" + words.join("|") + ")"; 76 | if (settings.wordsOnly) { 77 | pattern = "\\b" + pattern + "\\b"; 78 | } 79 | var re = new RegExp(pattern, flag); 80 | 81 | return this.each(function () { 82 | jQuery.highlight(this, re, settings.element, settings.className); 83 | }); 84 | }; 85 | 86 | }); 87 | -------------------------------------------------------------------------------- /docs/libs/gitbook/js/plugin-sharing.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var SITES = { 3 | 'github': { 4 | 'label': 'Github', 5 | 'icon': 'fa fa-github', 6 | 'onClick': function(e) { 7 | e.preventDefault(); 8 | var repo = $('meta[name="github-repo"]').attr('content'); 9 | if (typeof repo === 'undefined') throw("Github repo not defined"); 10 | window.open("https://github.com/"+repo); 11 | } 12 | }, 13 | 'facebook': { 14 | 'label': 'Facebook', 15 | 'icon': 'fa fa-facebook', 16 | 'onClick': function(e) { 17 | e.preventDefault(); 18 | window.open("http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(location.href)); 19 | } 20 | }, 21 | 'twitter': { 22 | 'label': 'Twitter', 23 | 'icon': 'fa fa-twitter', 24 | 'onClick': function(e) { 25 | e.preventDefault(); 26 | window.open("http://twitter.com/intent/tweet?text="+document.title+"&url="+encodeURIComponent(location.href)+"&hashtags=rmarkdown,bookdown"); 27 | } 28 | }, 29 | 'linkedin': { 30 | 'label': 'LinkedIn', 31 | 'icon': 'fa fa-linkedin', 32 | 'onClick': function(e) { 33 | e.preventDefault(); 34 | window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)); 35 | } 36 | }, 37 | 'weibo': { 38 | 'label': 'Weibo', 39 | 'icon': 'fa fa-weibo', 40 | 'onClick': function(e) { 41 | e.preventDefault(); 42 | window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)); 43 | } 44 | }, 45 | 'instapaper': { 46 | 'label': 'Instapaper', 47 | 'icon': 'fa fa-italic', 48 | 'onClick': function(e) { 49 | e.preventDefault(); 50 | window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href)); 51 | } 52 | }, 53 | 'vk': { 54 | 'label': 'VK', 55 | 'icon': 'fa fa-vk', 56 | 'onClick': function(e) { 57 | e.preventDefault(); 58 | window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href)); 59 | } 60 | } 61 | }; 62 | 63 | 64 | 65 | gitbook.events.bind("start", function(e, config) { 66 | var opts = config.sharing; 67 | if (!opts) return; 68 | 69 | // Create dropdown menu 70 | var menu = _.chain(opts.all) 71 | .map(function(id) { 72 | var site = SITES[id]; 73 | if (!site) return; 74 | return { 75 | text: site.label, 76 | onClick: site.onClick 77 | }; 78 | }) 79 | .compact() 80 | .value(); 81 | 82 | // Create main button with dropdown 83 | if (menu.length > 0) { 84 | gitbook.toolbar.createButton({ 85 | icon: 'fa fa-share-alt', 86 | label: 'Share', 87 | position: 'right', 88 | dropdown: [menu] 89 | }); 90 | } 91 | 92 | // Direct actions to share 93 | _.each(SITES, function(site, sideId) { 94 | if (!opts[sideId]) return; 95 | 96 | gitbook.toolbar.createButton({ 97 | icon: site.icon, 98 | label: site.label, 99 | title: site.label, 100 | position: 'right', 101 | onClick: site.onClick 102 | }); 103 | }); 104 | }); 105 | }); 106 | -------------------------------------------------------------------------------- /packages.bib: -------------------------------------------------------------------------------- 1 | @Manual{R-base, 2 | title = {R: A Language and Environment for Statistical Computing}, 3 | author = {{R Core Team}}, 4 | organization = {R Foundation for Statistical Computing}, 5 | address = {Vienna, Austria}, 6 | year = {2020}, 7 | url = {https://www.R-project.org/}, 8 | } 9 | @Manual{R-bookdown, 10 | title = {bookdown: Authoring Books and Technical Documents with R Markdown}, 11 | author = {Yihui Xie}, 12 | year = {2020}, 13 | note = {R package version 0.19}, 14 | url = {https://CRAN.R-project.org/package=bookdown}, 15 | } 16 | @Manual{R-data.table, 17 | title = {data.table: Extension of `data.frame`}, 18 | author = {Matt Dowle and Arun Srinivasan}, 19 | year = {2019}, 20 | note = {R package version 1.12.8}, 21 | url = {https://CRAN.R-project.org/package=data.table}, 22 | } 23 | @Manual{R-dplyr, 24 | title = {dplyr: A Grammar of Data Manipulation}, 25 | author = {Hadley Wickham and Romain François and Lionel Henry and Kirill Müller}, 26 | year = {2020}, 27 | note = {R package version 0.8.5}, 28 | url = {https://CRAN.R-project.org/package=dplyr}, 29 | } 30 | @Manual{R-ggplot2, 31 | title = {ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics}, 32 | author = {Hadley Wickham and Winston Chang and Lionel Henry and Thomas Lin Pedersen and Kohske Takahashi and Claus Wilke and Kara Woo and Hiroaki Yutani and Dewey Dunnington}, 33 | year = {2020}, 34 | note = {R package version 3.3.0}, 35 | url = {https://CRAN.R-project.org/package=ggplot2}, 36 | } 37 | @Manual{R-knitr, 38 | title = {knitr: A General-Purpose Package for Dynamic Report Generation in R}, 39 | author = {Yihui Xie}, 40 | year = {2020}, 41 | note = {R package version 1.28}, 42 | url = {https://CRAN.R-project.org/package=knitr}, 43 | } 44 | @Manual{R-readr, 45 | title = {readr: Read Rectangular Text Data}, 46 | author = {Hadley Wickham and Jim Hester and Romain Francois}, 47 | year = {2018}, 48 | note = {R package version 1.3.1}, 49 | url = {https://CRAN.R-project.org/package=readr}, 50 | } 51 | @Manual{R-readxl, 52 | title = {readxl: Read Excel Files}, 53 | author = {Hadley Wickham and Jennifer Bryan}, 54 | year = {2019}, 55 | note = {R package version 1.3.1}, 56 | url = {https://CRAN.R-project.org/package=readxl}, 57 | } 58 | @Manual{R-rmarkdown, 59 | title = {rmarkdown: Dynamic Documents for R}, 60 | author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone}, 61 | year = {2020}, 62 | note = {R package version 2.1}, 63 | url = {https://CRAN.R-project.org/package=rmarkdown}, 64 | } 65 | @Book{bookdown2016, 66 | title = {bookdown: Authoring Books and Technical Documents with {R} Markdown}, 67 | author = {Yihui Xie}, 68 | publisher = {Chapman and Hall/CRC}, 69 | address = {Boca Raton, Florida}, 70 | year = {2016}, 71 | note = {ISBN 978-1138700109}, 72 | url = {https://github.com/rstudio/bookdown}, 73 | } 74 | @Book{ggplot22016, 75 | author = {Hadley Wickham}, 76 | title = {ggplot2: Elegant Graphics for Data Analysis}, 77 | publisher = {Springer-Verlag New York}, 78 | year = {2016}, 79 | isbn = {978-3-319-24277-4}, 80 | url = {https://ggplot2.tidyverse.org}, 81 | } 82 | @Book{knitr2015, 83 | title = {Dynamic Documents with {R} and knitr}, 84 | author = {Yihui Xie}, 85 | publisher = {Chapman and Hall/CRC}, 86 | address = {Boca Raton, Florida}, 87 | year = {2015}, 88 | edition = {2nd}, 89 | note = {ISBN 978-1498716963}, 90 | url = {https://yihui.org/knitr/}, 91 | } 92 | @InCollection{knitr2014, 93 | booktitle = {Implementing Reproducible Computational Research}, 94 | editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng}, 95 | title = {knitr: A Comprehensive Tool for Reproducible Research in {R}}, 96 | author = {Yihui Xie}, 97 | publisher = {Chapman and Hall/CRC}, 98 | year = {2014}, 99 | note = {ISBN 978-1466561595}, 100 | url = {http://www.crcpress.com/product/isbn/9781466561595}, 101 | } 102 | @Book{rmarkdown2018, 103 | title = {R Markdown: The Definitive Guide}, 104 | author = {Yihui Xie and J.J. Allaire and Garrett Grolemund}, 105 | publisher = {Chapman and Hall/CRC}, 106 | address = {Boca Raton, Florida}, 107 | year = {2018}, 108 | note = {ISBN 9781138359338}, 109 | url = {https://bookdown.org/yihui/rmarkdown}, 110 | } 111 | -------------------------------------------------------------------------------- /docs/libs/gitbook/js/plugin-fontsettings.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var fontState; 3 | 4 | var THEMES = { 5 | "white": 0, 6 | "sepia": 1, 7 | "night": 2 8 | }; 9 | 10 | var FAMILY = { 11 | "serif": 0, 12 | "sans": 1 13 | }; 14 | 15 | // Save current font settings 16 | function saveFontSettings() { 17 | gitbook.storage.set("fontState", fontState); 18 | update(); 19 | } 20 | 21 | // Increase font size 22 | function enlargeFontSize(e) { 23 | e.preventDefault(); 24 | if (fontState.size >= 4) return; 25 | 26 | fontState.size++; 27 | saveFontSettings(); 28 | }; 29 | 30 | // Decrease font size 31 | function reduceFontSize(e) { 32 | e.preventDefault(); 33 | if (fontState.size <= 0) return; 34 | 35 | fontState.size--; 36 | saveFontSettings(); 37 | }; 38 | 39 | // Change font family 40 | function changeFontFamily(index, e) { 41 | e.preventDefault(); 42 | 43 | fontState.family = index; 44 | saveFontSettings(); 45 | }; 46 | 47 | // Change type of color 48 | function changeColorTheme(index, e) { 49 | e.preventDefault(); 50 | 51 | var $book = $(".book"); 52 | 53 | if (fontState.theme !== 0) 54 | $book.removeClass("color-theme-"+fontState.theme); 55 | 56 | fontState.theme = index; 57 | if (fontState.theme !== 0) 58 | $book.addClass("color-theme-"+fontState.theme); 59 | 60 | saveFontSettings(); 61 | }; 62 | 63 | function update() { 64 | var $book = gitbook.state.$book; 65 | 66 | $(".font-settings .font-family-list li").removeClass("active"); 67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); 68 | 69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); 70 | $book.addClass("font-size-"+fontState.size); 71 | $book.addClass("font-family-"+fontState.family); 72 | 73 | if(fontState.theme !== 0) { 74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); 75 | $book.addClass("color-theme-"+fontState.theme); 76 | } 77 | }; 78 | 79 | function init(config) { 80 | var $bookBody, $book; 81 | 82 | //Find DOM elements. 83 | $book = gitbook.state.$book; 84 | $bookBody = $book.find(".book-body"); 85 | 86 | // Instantiate font state object 87 | fontState = gitbook.storage.get("fontState", { 88 | size: config.size || 2, 89 | family: FAMILY[config.family || "sans"], 90 | theme: THEMES[config.theme || "white"] 91 | }); 92 | 93 | update(); 94 | }; 95 | 96 | 97 | gitbook.events.bind("start", function(e, config) { 98 | var opts = config.fontsettings; 99 | if (!opts) return; 100 | 101 | // Create buttons in toolbar 102 | gitbook.toolbar.createButton({ 103 | icon: 'fa fa-font', 104 | label: 'Font Settings', 105 | className: 'font-settings', 106 | dropdown: [ 107 | [ 108 | { 109 | text: 'A', 110 | className: 'font-reduce', 111 | onClick: reduceFontSize 112 | }, 113 | { 114 | text: 'A', 115 | className: 'font-enlarge', 116 | onClick: enlargeFontSize 117 | } 118 | ], 119 | [ 120 | { 121 | text: 'Serif', 122 | onClick: _.partial(changeFontFamily, 0) 123 | }, 124 | { 125 | text: 'Sans', 126 | onClick: _.partial(changeFontFamily, 1) 127 | } 128 | ], 129 | [ 130 | { 131 | text: 'White', 132 | onClick: _.partial(changeColorTheme, 0) 133 | }, 134 | { 135 | text: 'Sepia', 136 | onClick: _.partial(changeColorTheme, 1) 137 | }, 138 | { 139 | text: 'Night', 140 | onClick: _.partial(changeColorTheme, 2) 141 | } 142 | ] 143 | ] 144 | }); 145 | 146 | 147 | // Init current settings 148 | init(opts); 149 | }); 150 | }); 151 | 152 | 153 | -------------------------------------------------------------------------------- /latex/template.tex: -------------------------------------------------------------------------------- 1 | \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$} 2 | $if(beamerarticle)$ 3 | \usepackage{beamerarticle} % needs to be loaded first 4 | $endif$ 5 | $if(fontfamily)$ 6 | \usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$} 7 | $else$ 8 | \usepackage{lmodern} 9 | $endif$ 10 | $if(linestretch)$ 11 | \usepackage{setspace} 12 | \setstretch{$linestretch$} 13 | $endif$ 14 | \usepackage{amssymb,amsmath} 15 | \usepackage{ifxetex,ifluatex} 16 | \usepackage{fixltx2e} % provides \textsubscript 17 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 18 | \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc} 19 | \usepackage[utf8]{inputenc} 20 | $if(euro)$ 21 | \usepackage{eurosym} 22 | $endif$ 23 | \else % if luatex or xelatex 24 | \ifxetex 25 | \usepackage{xltxtra,xunicode} 26 | \else 27 | \usepackage{fontspec} 28 | \fi 29 | \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase} 30 | $for(fontfamilies)$ 31 | \newfontfamily{$fontfamilies.name$}[$fontfamilies.options$]{$fontfamilies.font$} 32 | $endfor$ 33 | $if(euro)$ 34 | \newcommand{\euro}{€} 35 | $endif$ 36 | $if(mainfont)$ 37 | \setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$} 38 | $endif$ 39 | $if(sansfont)$ 40 | \setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$]{$sansfont$} 41 | $endif$ 42 | $if(monofont)$ 43 | \setmonofont[Mapping=tex-ansi$if(monofontoptions)$,$for(monofontoptions)$$monofontoptions$$sep$,$endfor$$endif$]{$monofont$} 44 | $endif$ 45 | $if(CJKmainfont)$ 46 | \usepackage{xeCJK} 47 | \setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$} 48 | $endif$ 49 | \fi 50 | % use upquote if available, for straight quotes in verbatim environments 51 | \IfFileExists{upquote.sty}{\usepackage{upquote}}{} 52 | % use microtype if available 53 | \IfFileExists{microtype.sty}{% 54 | \usepackage{microtype} 55 | \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts 56 | }{} 57 | $if(geometry)$ 58 | \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} 59 | $endif$ 60 | \usepackage[unicode=true]{hyperref} 61 | $if(colorlinks)$ 62 | \PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref 63 | $endif$ 64 | \hypersetup{ 65 | $if(title-meta)$ 66 | pdftitle={$title-meta$}, 67 | $endif$ 68 | $if(author-meta)$ 69 | pdfauthor={$author-meta$}, 70 | $endif$ 71 | $if(keywords)$ 72 | pdfkeywords={$for(keywords)$$keywords$$sep$, $endfor$}, 73 | $endif$ 74 | $if(colorlinks)$ 75 | colorlinks=true, 76 | linkcolor=$if(linkcolor)$$linkcolor$$else$Maroon$endif$, 77 | citecolor=$if(citecolor)$$citecolor$$else$Blue$endif$, 78 | urlcolor=$if(urlcolor)$$urlcolor$$else$Blue$endif$, 79 | $else$ 80 | pdfborder={0 0 0}, 81 | $endif$ 82 | breaklinks=true} 83 | \urlstyle{same} % don't use monospace font for urls 84 | $if(lang)$ 85 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 86 | \usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel} 87 | $if(babel-newcommands)$ 88 | $babel-newcommands$ 89 | $endif$ 90 | \else 91 | \usepackage{polyglossia} 92 | \setmainlanguage[$polyglossia-lang.options$]{$polyglossia-lang.name$} 93 | $for(polyglossia-otherlangs)$ 94 | \setotherlanguage[$polyglossia-otherlangs.options$]{$polyglossia-otherlangs.name$} 95 | $endfor$ 96 | \fi 97 | $endif$ 98 | $if(natbib)$ 99 | \usepackage{natbib} 100 | \bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} 101 | $endif$ 102 | $if(biblatex)$ 103 | \usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} 104 | $for(bibliography)$ 105 | \addbibresource{$bibliography$} 106 | $endfor$ 107 | $endif$ 108 | $if(listings)$ 109 | \usepackage{listings} 110 | $endif$ 111 | $if(lhs)$ 112 | \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} 113 | $endif$ 114 | $if(highlighting-macros)$ 115 | $highlighting-macros$ 116 | $endif$ 117 | $if(verbatim-in-note)$ 118 | \usepackage{fancyvrb} 119 | \VerbatimFootnotes % allows verbatim text in footnotes 120 | $endif$ 121 | $if(tables)$ 122 | \usepackage{longtable,booktabs} 123 | % Fix footnotes in tables (requires footnote package) 124 | \IfFileExists{footnote.sty}{\usepackage{footnote}\makesavenoteenv{long table}}{} 125 | $endif$ 126 | $if(graphics)$ 127 | \usepackage{graphicx,grffile} 128 | \makeatletter 129 | \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} 130 | \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} 131 | \makeatother 132 | % Scale images if necessary, so that they will not overflow the page 133 | % margins by default, and it is still possible to overwrite the defaults 134 | % using explicit options in \includegraphics[width, height, ...]{} 135 | \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} 136 | $endif$ 137 | $if(links-as-notes)$ 138 | % Make links footnotes instead of hotlinks: 139 | \renewcommand{\href}[2]{#2\footnote{\url{#1}}} 140 | $endif$ 141 | $if(strikeout)$ 142 | \usepackage[normalem]{ulem} 143 | % avoid problems with \sout in headers with hyperref: 144 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 145 | $endif$ 146 | $if(indent)$ 147 | $else$ 148 | \IfFileExists{parskip.sty}{% 149 | \usepackage{parskip} 150 | }{% else 151 | \setlength{\parindent}{0pt} 152 | \setlength{\parskip}{6pt plus 2pt minus 1pt} 153 | } 154 | $endif$ 155 | \setlength{\emergencystretch}{3em} % prevent overfull lines 156 | \providecommand{\tightlist}{% 157 | \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} 158 | $if(numbersections)$ 159 | \setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$} 160 | $else$ 161 | \setcounter{secnumdepth}{0} 162 | $endif$ 163 | $if(subparagraph)$ 164 | $else$ 165 | % Redefines (sub)paragraphs to behave more like sections 166 | \ifx\paragraph\undefined\else 167 | \let\oldparagraph\paragraph 168 | \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} 169 | \fi 170 | \ifx\subparagraph\undefined\else 171 | \let\oldsubparagraph\subparagraph 172 | \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} 173 | \fi 174 | $endif$ 175 | $if(dir)$ 176 | \ifxetex 177 | % load bidi as late as possible as it modifies e.g. graphicx 178 | $if(latex-dir-rtl)$ 179 | \usepackage[RTLdocument]{bidi} 180 | $else$ 181 | \usepackage{bidi} 182 | $endif$ 183 | \fi 184 | \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex 185 | \TeXXeTstate=1 186 | \newcommand{\RL}[1]{\beginR #1\endR} 187 | \newcommand{\LR}[1]{\beginL #1\endL} 188 | \newenvironment{RTL}{\beginR}{\endR} 189 | \newenvironment{LTR}{\beginL}{\endL} 190 | \fi 191 | $endif$ 192 | 193 | % set default figure placement to htbp 194 | \makeatletter 195 | \def\fps@figure{htbp} 196 | \makeatother 197 | 198 | $for(header-includes)$ 199 | $header-includes$ 200 | $endfor$ 201 | 202 | $if(title)$ 203 | \title{$title$$if(thanks)$\thanks{$thanks$}$endif$} 204 | $endif$ 205 | $if(subtitle)$ 206 | \providecommand{\subtitle}[1]{} 207 | \subtitle{$subtitle$} 208 | $endif$ 209 | $if(author)$ 210 | \author{$for(author)$$author$$sep$ \and $endfor$} 211 | $endif$ 212 | $if(institute)$ 213 | \providecommand{\institute}[1]{} 214 | \institute{$for(institute)$$institute$$sep$ \and $endfor$} 215 | $endif$ 216 | \date{$date$} 217 | 218 | \begin{document} 219 | $if(title)$ 220 | \maketitle 221 | $endif$ 222 | $if(abstract)$ 223 | \begin{abstract} 224 | $abstract$ 225 | \end{abstract} 226 | $endif$ 227 | 228 | $for(include-before)$ 229 | $include-before$ 230 | 231 | $endfor$ 232 | $if(toc)$ 233 | { 234 | \setcounter{tocdepth}{$toc-depth$} 235 | \tableofcontents 236 | } 237 | $endif$ 238 | $if(lot)$ 239 | \listoftables 240 | $endif$ 241 | $if(lof)$ 242 | \listoffigures 243 | $endif$ 244 | $body$ 245 | 246 | $if(natbib)$ 247 | $if(bibliography)$ 248 | $if(biblio-title)$ 249 | $if(book-class)$ 250 | \renewcommand\bibname{$biblio-title$} 251 | $else$ 252 | \renewcommand\refname{$biblio-title$} 253 | $endif$ 254 | $endif$ 255 | \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} 256 | 257 | $endif$ 258 | $endif$ 259 | $if(biblatex)$ 260 | \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ 261 | 262 | $endif$ 263 | $for(include-after)$ 264 | $include-after$ 265 | 266 | $endfor$ 267 | \end{document} 268 | -------------------------------------------------------------------------------- /docs/libs/gitbook/js/plugin-search.js: -------------------------------------------------------------------------------- 1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var index = null; 3 | var $searchInput, $searchLabel, $searchForm; 4 | var $highlighted = [], hi, hiOpts = { className: 'search-highlight' }; 5 | var collapse = false, toc_visible = []; 6 | 7 | // Use a specific index 8 | function loadIndex(data) { 9 | // [Yihui] In bookdown, I use a character matrix to store the chapter 10 | // content, and the index is dynamically built on the client side. 11 | // Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search 12 | // We can certainly do that via R packages V8 and jsonlite, but let's 13 | // see how slow it really is before improving it. On the other hand, 14 | // lunr cannot handle non-English text very well, e.g. the default 15 | // tokenizer cannot deal with Chinese text, so we may want to replace 16 | // lunr with a dumb simple text matching approach. 17 | index = lunr(function () { 18 | this.ref('url'); 19 | this.field('title', { boost: 10 }); 20 | this.field('body'); 21 | }); 22 | data.map(function(item) { 23 | index.add({ 24 | url: item[0], 25 | title: item[1], 26 | body: item[2] 27 | }); 28 | }); 29 | } 30 | 31 | // Fetch the search index 32 | function fetchIndex() { 33 | return $.getJSON(gitbook.state.basePath+"/search_index.json") 34 | .then(loadIndex); // [Yihui] we need to use this object later 35 | } 36 | 37 | // Search for a term and return results 38 | function search(q) { 39 | if (!index) return; 40 | 41 | var results = _.chain(index.search(q)) 42 | .map(function(result) { 43 | var parts = result.ref.split("#"); 44 | return { 45 | path: parts[0], 46 | hash: parts[1] 47 | }; 48 | }) 49 | .value(); 50 | 51 | // [Yihui] Highlight the search keyword on current page 52 | $highlighted = results.length === 0 ? [] : $('.page-inner') 53 | .unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight'); 54 | scrollToHighlighted(0); 55 | 56 | return results; 57 | } 58 | 59 | // [Yihui] Scroll the chapter body to the i-th highlighted string 60 | function scrollToHighlighted(d) { 61 | var n = $highlighted.length; 62 | hi = hi === undefined ? 0 : hi + d; 63 | // navignate to the previous/next page in the search results if reached the top/bottom 64 | var b = hi < 0; 65 | if (d !== 0 && (b || hi >= n)) { 66 | var path = currentPath(), n2 = toc_visible.length; 67 | if (n2 === 0) return; 68 | for (var i = b ? 0 : n2; (b && i < n2) || (!b && i >= 0); i += b ? 1 : -1) { 69 | if (toc_visible.eq(i).data('path') === path) break; 70 | } 71 | i += b ? -1 : 1; 72 | if (i < 0) i = n2 - 1; 73 | if (i >= n2) i = 0; 74 | var lnk = toc_visible.eq(i).find('a[href$=".html"]'); 75 | if (lnk.length) lnk[0].click(); 76 | return; 77 | } 78 | if (n === 0) return; 79 | var $p = $highlighted.eq(hi); 80 | $p[0].scrollIntoView(); 81 | $highlighted.css('background-color', ''); 82 | // an orange background color on the current item and removed later 83 | $p.css('background-color', 'orange'); 84 | setTimeout(function() { 85 | $p.css('background-color', ''); 86 | }, 2000); 87 | } 88 | 89 | function currentPath() { 90 | var href = window.location.pathname; 91 | href = href.substr(href.lastIndexOf('/') + 1); 92 | return href === '' ? 'index.html' : href; 93 | } 94 | 95 | // Create search form 96 | function createForm(value) { 97 | if ($searchForm) $searchForm.remove(); 98 | if ($searchLabel) $searchLabel.remove(); 99 | if ($searchInput) $searchInput.remove(); 100 | 101 | $searchForm = $('
    ', { 102 | 'class': 'book-search', 103 | 'role': 'search' 104 | }); 105 | 106 | $searchLabel = $('