前言

荃者所以在鱼,得鱼而忘荃;蹄者所以在兔;得兔而忘蹄;言者所以在意,得意而忘言。吾安得夫忘言之人而与之言哉!

— 摘自 《庄子·杂篇·物》

The fish trap exists because of the fish; once you’ve gotten the fish, you can forget the trap. The rabbit snare exists because of the rabbit; once you’ve gotten the rabbit, you can forget the snare. Words exist because of meaning; once you’ve gotten the meaning, you can forget the words. Where can I find a man who has forgotten words so I can have a word with him ?1

— Chuang Tzu

  1. 把平时遇到的问题分类汇总形成一本笔记,用以时常查看和更新。
  2. 网罗精美的案例,学习之,应用之
  3. 挑选感兴趣的新技能,钻研之
  4. 学习心得和体会,尤其是那些年的淌坑经历
  5. 从使用者到开发者蜕变,先啃一下 Hadley Wickham 的几本书:
  6. 要写书搭网站,先看一下 Yihui Xie 的书

致谢

虚位以待壮士

Thanks go to all contributers in alphabetical order: .

非常感谢谁谁以及谁谁对我的帮助。

黄湘云
于矿大宝源公寓

结构

第一章:数学符号说明 第二章:基础知识

  • R语言基础、高级技巧

你好,世界。我写了一本书。这本书是这样的,第 3 章介绍了啥啥,第 4 章说了啥啥,然后是啥啥……

后记

这本书是在 RStudio 内用 R Markdown 写的, Git 控制版本, bookdown 组织章节, knitr 将 R Markdown 源文件转化为 Markdown 文件, Pandoc 再将 Markdown 文件转化为 HTML 文档,而要转化为 PDF 文档则另外需要 TinyTeX 发行版2 和来自 rticles (Allaire et al. 2018) 包的模板(一个基于 Pandoc 的 LaTeX 模板,两个美元符号包含的就是变量,变量基本上是 LaTeX 包的设置选项)。这个网站是通过 Travis-CI 把编译结果(即 _book 目录)推送到 Netlify,实现部署。在 Travis-CI 和 Netlify 都与 Github 绑定的情况下,源代码一发生改变就会触发编译和部署,即持续集成和连续部署,你正在阅读的是 2018-12-14 在 本地构建的。

如果编译和部署成功,你会看到一个绿色的指示器,否则指示器显示红色。Build Status

说明

sourceserifpro 设为默认英文字体,inconsolata 用于代码显示,R 包名称在文中以粗体显示,代码块输出用 #> 表示,以区分普通的代码注释 #

我用了两个 R 包编译这本书,分别是 knitr (Xie 2015)bookdown (Xie 2016)。绘图使用的中文字体是思源宋体和思源黑体, showtext 包安装和调用,tikzDevicefontcm 处理其中的数学公式,xkcd 设置漫画手写体风格,以下是我的 R 进程信息:

xfun::session_info(packages = c('rmarkdown','bookdown'))
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 8.1 x64 (build 9600)
#> 
#> Locale:
#>   LC_COLLATE=Chinese (Simplified)_China.936 
#>   LC_CTYPE=Chinese (Simplified)_China.936   
#>   LC_MONETARY=Chinese (Simplified)_China.936
#>   LC_NUMERIC=C                              
#>   LC_TIME=Chinese (Simplified)_China.936    
#> 
#> Package version:
#>   base64enc_0.1.3 bookdown_0.8    digest_0.6.18   evaluate_0.12  
#>   glue_1.3.0      graphics_3.5.1  grDevices_3.5.1 highr_0.7      
#>   htmltools_0.3.6 jsonlite_1.6    knitr_1.21      magrittr_1.5   
#>   markdown_0.9    methods_3.5.1   mime_0.6        Rcpp_1.0.0     
#>   rmarkdown_1.11  stats_3.5.1     stringi_1.2.4   stringr_1.3.1  
#>   tinytex_0.9     tools_3.5.1     utils_3.5.1     xfun_0.4       
#>   yaml_2.2.0     
#> 
#> Pandoc version: 2.5
# rstan::stan_version()
# blogdown::hugo_version()
cat(system("xelatex -v", intern = TRUE), sep = "\n")
#> XeTeX 3.14159265-2.6-0.99999 (TeX Live 2018/W32TeX)
#> kpathsea version 6.3.0
#> Copyright 2018 SIL International, Jonathan Kew and Khaled Hosny.
#> There is NO warranty.  Redistribution of this software is
#> covered by the terms of both the XeTeX copyright and
#> the Lesser GNU General Public License.
#> For more information about these matters, see the file
#> named COPYING and the XeTeX source.
#> Primary author of XeTeX: Jonathan Kew.
#> Compiled with ICU version 61.1; using 61.1
#> Compiled with zlib version 1.2.11; using 1.2.11
#> Compiled with FreeType2 version 2.9.1; using 2.9.1
#> Compiled with Graphite2 version 1.3.11; using 1.3.11
#> Compiled with HarfBuzz version 1.7.6; using 1.7.6
#> Compiled with libpng version 1.6.34; using 1.6.34
#> Compiled with poppler version 0.64.0
#> Compiled with fontconfig version 2.13.0; using 2.13.0
cat(system2("gcc", args = "-v", stderr = TRUE, stdout = TRUE), sep = "\n")
#> Using built-in specs.
#> COLLECT_GCC=c:\Rtools\mingw_64\bin\gcc.exe
#> COLLECT_LTO_WRAPPER=c:/Rtools/mingw_64/bin/../libexec/gcc/x86_64-w64-mingw32/4.9.3/lto-wrapper.exe
#> Target: x86_64-w64-mingw32
#> Configured with: ../../../src/gcc-4.9.3/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-static --disable-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/lib '
#> Thread model: posix
#> gcc version 4.9.3 (x86_64-posix-seh, Built by MinGW-W64 project)
cat(system2("g++", args = "-v", stderr = TRUE, stdout = TRUE), sep = "\n")
#> Using built-in specs.
#> COLLECT_GCC=c:\Rtools\mingw_64\bin\G__~1.EXE
#> COLLECT_LTO_WRAPPER=c:/Rtools/mingw_64/bin/../libexec/gcc/x86_64-w64-mingw32/4.9.3/lto-wrapper.exe
#> Target: x86_64-w64-mingw32
#> Configured with: ../../../src/gcc-4.9.3/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-static --disable-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/lib '
#> Thread model: posix
#> gcc version 4.9.3 (x86_64-posix-seh, Built by MinGW-W64 project)

授权

本书采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 许可,请君自重,别没事儿拿去传个什么新浪爱问、百度文库以及 XX 经济论坛,项目中代码使用 MIT 协议 开源

参考文献

Allaire, JJ, Yihui Xie, R Foundation, Hadley Wickham, Journal of Statistical Software, Ramnath Vaidyanathan, Association for Computing Machinery, et al. 2018. Rticles: Article Formats for R Markdown. https://CRAN.R-project.org/package=rticles.

Xie, Yihui. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. http://yihui.name/knitr/.

Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.