跟着运来兄搭建自己的生物信息小书房。趁年轻,读几本硬书,到老了慢慢反刍。
R语言是主要在学术界用的编程语言,写作是其内涵之义,于是有了 RMarkdown。基于RMarkdown语法yihui进一步扩张了RMarkdown的应用,于是有了bookdown及其plus,以及blogdown。字面意思,前者是用来写书的后者是用来写博客的。每一个喜欢R语言不巧又同时喜欢写作的人,遇到这两个包都会有抑制不住的好奇心。余,概莫能外。
在开始写书之前,首先要把硬件配置起来:R、 RStudio、LaXTex、以及pandoc这写软件要安装起来。
bookdown 官网:https://bookdown.org/ tinytex官网 https://yihui.org/tinytex/cn/
写作,既是内容的艺术也是版式的艺术。bookdown把版式这一块结合tinytex做到了尽可能的极致,让写作者可以安心喻内容,而不必花太多心思在版式上。可以说解决了书籍的排版问题。经历过毕业论文排版的同学,对论文的排版经历应该记忆犹新吧。当面对一本书的时候,这个浩大的工作往往让写作者无从下手,于是才发展出一个专业来。现在,bookdown可以让我们省去排版的烦恼,直接写起来,而且里面还有大量的版式可以使用。
今天主要是来初探一番bookdown,写书是思想的火花在碰撞,有了想法,版式不是问题啦。
代码语言:javascript复制library(bookdownplus)
library(tinytex)
安装tinytex
代码语言:javascript复制tinytex::install_tinytex(TRUE)
tinytex::latexmk()
查看简单的配置环境
代码语言:javascript复制> xfun::session_info('rmarkdown')
R version 3.5.1 (2018-07-02)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1, RStudio 1.1.456
Locale: C
Package version:
Rcpp_1.0.3 base64enc_0.1.3 digest_0.6.22 evaluate_0.14 glue_1.3.1 grDevices_3.5.1 graphics_3.5.1 highr_0.8
htmltools_0.4.0 jsonlite_1.6 knitr_1.26 magrittr_1.5 markdown_1.1 methods_3.5.1 mime_0.7 rlang_0.4.1
rmarkdown_1.17 stats_3.5.1 stringi_1.4.3 stringr_1.4.0 tinytex_0.17 tools_3.5.1 utils_3.5.1 xfun_0.11
yaml_2.2.0
Pandoc version: 1.19.2.1
> tinytex::tinytex_root()
[1] "C:\Users\Administrator\AppData\Roaming\TinyTeX"
代码语言:javascript复制> (function() {
tinytex:::tweak_path()
print(Sys.which('pdflatex'))
system2('pdflatex', '--version')
})()
pdflatex
"C:\Users\ADMINI~1\AppData\Roaming\TinyTeX\bin\win32\pdflatex.exe"
pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX)
kpathsea version 6.3.1
Copyright 2019 Han The Thanh (pdfTeX) et al.
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.36; using libpng 1.6.36
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.01
代码语言:javascript复制> p = tinytex:::win_app_dir('TinyTeX', 'bin', 'win32', 'pdflatex.exe')
> file.info(p)
size isdir mode mtime ctime
C:\Users\Administrator\AppData\Roaming/TinyTeX/bin/win32/pdflatex.exe 1536 FALSE 777 2019-12-27 13:13:31 2019-12-26 23:18:14
atime exe
C:\Users\Administrator\AppData\Roaming/TinyTeX/bin/win32/pdflatex.exe 2019-12-26 23:18:14 win32
下载一个模板看看:
代码语言:javascript复制bookdownplus::bookdownplus(template = template()[5],more_output = more_output()[1:3])
> list.dirs(getwd())
[1] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown"
[2] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user"
[3] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6"
[4] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/console06"
[5] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/ctx"
[6] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/explorer-cache"
[7] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/pcs"
[8] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/presentation"
[9] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/profiles-cache"
[10] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/sources"
[11] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/sources/per"
[12] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/sources/per/t"
[13] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/sources/per/u"
[14] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/sources/prop"
[15] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/sources/s-7A3B3637"
[16] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/viewer-cache"
[17] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/79AF59C6/viewer_history"
[18] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared"
[19] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks"
[20] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/68B5A731-index"
[21] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/68B5A731-index/1"
[22] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/68B5A731-index/1/79AF59C67A3B3637"
[23] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/68B5A731-index/1/s"
[24] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/A33EE802-R_in_action"
[25] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/A33EE802-R_in_action/1"
[26] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/A33EE802-R_in_action/1/79AF59C6916CB969"
[27] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/A33EE802-R_in_action/1/s"
[28] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/DE9AEE1D-body"
[29] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/DE9AEE1D-body/1"
[30] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/DE9AEE1D-body/1/79AF59C67A3B3637"
[31] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/.Rproj.user/shared/notebooks/DE9AEE1D-body/1/s"
[32] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/_book"
[33] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/_bookdown_files"
[34] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/_bookdown_files/demo_zh_files"
[35] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/_bookdown_files/demo_zh_files/figure-latex"
[36] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/backup"
[37] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/bib"
[38] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/images"
[39] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/style"
[40] "G:/Desktop/Desktop/RStudio/Rmarkdown/Rmarkdown/tex"
在R的项目里面就可以看到:
书就在_book中放着,然后我们就可以用Markdown语法写书了:直接套用模板index.Rmd以及body.Rmd。
代码语言:javascript复制---
title: "单细胞转录组数据分析"
subtitle: "---方法、软件与程序"
author: "周运来"
date: "`r Sys.Date()`"
output:
bookdown::pdf_book:
keep_tex: yes
dev: "cairo_pdf"
latex_engine: xelatex
citation_package: natbib
template: tex/template_yihui_zh.tex
pandoc_args: --top-level-division=chapter
toc_depth: 3
toc_unnumbered: no
toc_appendix: yes
quote_footer: ["\begin{flushright}", "\end{flushright}"]
documentclass: ctexbook
bibliography: [bib/bib.bib]
biblio-style: apalike
link-citations: yes
colorlinks: no
lot: yes
lof: yes
geometry: [b5paper, tmargin=2.5cm, bmargin=2.5cm, lmargin=3.5cm, rmargin=2.5cm]
site: bookdown::bookdown_site
description: "一个简单的中文书示例。"
github-repo: yihui/bookdown-chinese
#cover-image: images/cover.jpg
---
mainmatter
布置好bookdown的环境,就像家里配置了一个印刷厂,在您写作的间隙就可以随时building出一本成品出来,随意浏览。也就是在写作的过程中,就可以随时了解书籍的版式是不是自己喜欢的。
下面几本和单细胞相关的电子书是bookdown格式写的,可以看一下:
代码语言:javascript复制Analysis of single cell RNA-seq data # 分析流程
https://scrnaseq-course.cog.sanger.ac.uk/website/index.html
Orchestrating Single-Cell Analysis with Bioconductor # 分析流程
http://bioconductor.org/books/release/OSCA/
Assigning cell types with SingleR # 细胞类型注释
http://bioconductor.org/books/release/SingleRBook/
Museum of Spatial Transcriptomics # 空转简史
https://bookdown.org/lambdamoses/museumst/
Archr # ATAC 分析
https://www.archrproject.com/bookdown/index.html#section