日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

别人的电子书,你的电子书,都在bookdown

發布時間:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 别人的电子书,你的电子书,都在bookdown 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

bookdown是著名R包作者謝益輝開發的,支持采用Rmarkdown (R代碼可以運行)或普通markdown編寫文檔,然后編譯成HTML, WORD, PDF, Epub等格式。樣式清新,使用簡單,值得擁有。(點擊閱讀原文,跳轉博客,所有外鏈可點)

在Bookdown的官網,有很多免費的用bookdown寫的R書籍,如Hadley Wickham等撰寫的《R for Data Science》,Roger D. Peng撰寫的《R Programming for Data Science》, 陳總的《液體活檢口袋書》,益輝的《R語言忍者秘笈》,《單細胞數據整體分析流程》https://hemberg-lab.github.io/scRNA.seq.course/index.html (初學單細胞分析可以完全照著這個,在學習過程中改進,我們也做了部分翻譯Hemberg-lab單細胞轉錄組數據分析(一))。

還有很多基于Bookdown的教程,一時也想不起來,歡迎大家補充。我們前面轉錄組和R培訓的教案也是用bookdown寫作的,后續再調整下格式,出一批電子書和紙質書,有意向和需求的歡迎聯系。

下面分2步講述,自己如何構建一個Bookdown書籍,第一部分是通過bookdown示例了解其基本功能和使用,第二部分是個人在使用過程中碰到的問題和解決方式。

基本使用

安裝必須軟件

Rstudio或Pandoc二選一, bookdown必須安裝。

  • Install Rstudio (version>1.0.0) (安裝和使用見Rstudio)

  • Install Pandoc (version>1.17.0.2)或者參照here。如果系統新,可以直接使用系統自帶的yum或apt-get;如果沒有權限或系統比較老,Pandoc的安裝可以使用conda,具體配置見Conda配置,配置好運行conda install -c conda-forge pandoc即可安裝。

  • In R install.packages("bookdown")

Demo示例

克隆或下載https://github.com/rstudio/bookdown-demo示例文件,編譯成功后,依葫蘆畫葫蘆修改.

編譯成書

運行下載的示例中的bash _build.sh,_book目錄下就是成書.

The content of _build.sh is:

#!/bin/sh Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')" # 生成pdf需要安裝好latex,如果不需要可以注釋掉 Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book')"

在前面的內容運轉起來后,再看后面的內容。

Customize our bookdown

準備Rmd文件

基本規則
  • 一個典型的bookdown文檔包含多個章節,每個章節在一個R Markdown文件里面 (文件的語法可以是pandoc支持的markdown語法,但后綴必須為Rmd)。

  • 每一個章節都必須以# Chapter title開頭。后面可以跟一段概括性語句,概述本章的內容,方便理解,同時也防止二級標題出現在這一頁。默認系統會按照文件名的順序合并Rmd文件。

  • 另外章節的順序也可在_bookdown.yml文件中通過rmd_files:["file1.Rmd", "file2.Rmd", ..]指定。

  • 如果有index.Rmd,index.Rmd總是出現在第一個位置。通常index.Rmd里面也需要有一章節,如果不需要對這一章節編號的話,可以寫作# Preface {-}, 關鍵是{-}。

  • 在第一個出現的Rmd文件中 (通常是index.Rmd),可以定義Pandoc相關的YAML metadata, 比如標題、作者、日期等 (去掉#及其后的內容)。

    ``` title: "My book" author: #可以寫多行信息,都會被當做Author處理 - "CT" - "CY" - "chentong_biology@163.com" date: "`r Sys.Date()`" documentclass: article #可以為book或article # 如果需要引用參考文獻,則添加下面三行內容 bibliography: [database.bib] ?#指定存儲參考文獻的bib文件,endote或zotero都可以導出這種引文格式 biblio-style: apalike ?#設定參考文獻顯示類型 link-citations: yes ``````{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE, fig.align="center", out.width="95%", fig.pos='H') knitr::opts_chunk$set(cache = FALSE, autodep=TRUE) set.seed(0304) ``` ~~~~~~
插入并引用圖片(外部圖片)

插入圖片最好使用knitr::include_graphics,可以同時適配HTML和PDF輸出。另外當目錄下同時存在name1.png和name1.pdf文件時,會自動選擇在HTML展示name1.png文件,在PDF輸出中引入name1.pdf格式的文件。

圖的標簽為fig-name(不能有下劃線),在引用時需使用如下格式\@ref(fig:fig-name),且fig.cap也要設置內容。

多張圖可以同時展示,圖的名字以vector形式傳給include_graphics,需要設置out.width=1/number-pics 和 fig.show="hold"。

Insert a single pic and refer as Figure \@ref(fig:fig-name). `echo=FALSE` will hide the code block and display the output of `r` command only. These options can be set globally as indicated below.```{r fig-name, fig.cap="Markdown supported string as caption", fig.align="center", echo=FALSE} knitr::include_graphics("images/1.png") ```Suppose we have 3 pictures in `images` folder with names as `Fig1_a`, `Fig1_b`, ?`Fig1_c`, ?we can refer to them using Figure \@ref(fig:fig1).```{r fig1, fig.cap="3 sub-plots.", fig.align="center", out.width=33%, fig.show="hold"} fig1 = list.files("images", pattern="Fig1_.*", full.names=T) knitr::include_graphics(fig1) ```Another way of including two pics.```{r fig-name2, ?out.width="49%", fig.show="hold", fig.cap="Markdown supported string as caption", ?fig.align="center", echo=FALSE} knitr::include_graphics(c("images/1.png", "images/2.png")) ``` ~~~~~~~~~~~~~~~~

如果圖或表的標題中有Markdown語法,輸出為HTML時是可以正確解析的,但是輸出為PDF時卻不可以。這時可以使用Text Reference。當圖或表的標題太長時,也可以使用Text Reference引用一段話作為圖和表的標題。

Here is normal text.(ref:pic-label) This line can be referred in **fig.cap** and markdown syntax is supported for both `HTML` and `PDF` output.```{r pic-label, fig.cap="(ref:pic-label)"} knitr::include_graphics("images/1.png") ``` ~

輸出PDF時不支持使用在線圖片,可以加一個判斷。

```{r fig-name, fig.cap="Markdown supported string as caption", fig.align="center", echo=FALSE} if (!file.exists(cover_file <- 'cover.jpg')){download.file(url, ?cover_file, ?mode = 'wb') } knitr::include_graphics(if (identical(knitr:::pandoc_to(), ?'html')) url else cover_file) ```
插入并引用表格(外部表格)

外部表格的名字中必須包含tab:, 然后是表格的實際名字,格式為(\#tab:table-name); 引用時使用Table \@ref(tab:table-name)。表格名字中不能有下劃線。

Check Table \@ref(tab:seq-sum) for detail.Table: (\#tab:seq-sum) Summary of sequencing reads 測序量總結 (對于雙端測序, ?*\_1* 表示左端reads, *\_2* 表示右端reads)---------------------------------------------------------------------- Sample ? ? Total reads ? ? Total bases Sequence length (nt) ? ? GC content (%) Encoding ? ? ? ? ? ? ? -------- ------------- --------------- ---------------------- ---------------- ----------------------- T8_1 ? ? ? ?37,106,941 ? 5,566,036,721 138-150 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?47 Sanger / Illumina 1.9 ?T8_2 ? ? ? ?37,106,941 ? 5,566,034,285 138-150 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?47 Sanger / Illumina 1.9 ? ----------------------------------------------------------------------
插入并引用表格(內部表格)

插入表格推薦使用knitr::kable,只要提供數據矩陣,用r讀取就可以了。

Check Table \@ref(tab:table-id) for detail.```{r table-id, include=FALSE} a <- as.data.frame(matrix(rnorm(20), nrow=4)) knitr::kable(a, caption="Test table", ?booktabs=TRUE) ``` ~
插入腳注

text^[footnote] is used to get the footnote.

where `type` may be `article`, ?`book`, ?`manual`, ?and so on.^[The type name is case-insensitive, ?so it does not matter if it is `manual`, ?`Manual`, ?or `MANUAL`.]
插入引文

假如我們的bib文件中內容如下,如果我們要引用這個文章,只要寫 [@chen_m6a_2015]就可以了。

@article{chen_m6a_2015,title = {m6A {RNA} {Methylation} {Is} {Regulated} by {MicroRNAs} and {Promotes} {Reprogramming} to {Pluripotency}},volume = {16},issn = {1934-5909, 1875-9777},url = {http://www.cell.com/cell-stem-cell/abstract/S1934-5909(15)00017-X},doi = {10.1016/j.stem.2015.01.016},language = {English},number = {3},urldate = {2016-12-08},journal = {Cell Stem Cell},author = {Chen, Tong and Hao, Ya-Juan and Zhang, Ying and Li, Miao-Miao and Wang, Meng and Han, Weifang and Wu, Yongsheng and Lv, Ying and Hao, Jie and Wang, Libin and Li, Ang and Yang, Ying and Jin, Kang-Xuan and Zhao, Xu and Li, Yuhuan and Ping, Xiao-Li and Lai, Wei-Yi and Wu, Li-Gang and Jiang, Guibin and Wang, Hai-Lin and Sang, Lisi and Wang, Xiu-Jie and Yang, Yun-Gui and Zhou, Qi},month = mar,year = {2015},pmid = {25683224},pages = {289--301}, }

準備YML配置文件

_bookdown.yml

配置輸入和輸出文件參數。

book_filename: "輸出文件的名字" output_dir: "輸出目錄的名字,默認_book" language:ui:chapter_name: ""
_output.yml

配置產生輸出文件的命令行參數。

bookdown::pdf_book:template: ehbio.tex #使用自己定制的pandoc latex模板includes: # or only customize part latex modulein_header: preamble.texbefore_body: latex/before_body.texafter_body: latex/after_body.texlatex_engine: xelatexcitation_package: natbibkeep_tex: yespandoc_args: --chapterstoc_depth: 3toc_unnumbered: notoc_appendix: yesquote_footer: ["\\VA{", "}{}"] bookdown::epub_book:stylesheet: css/style.css bookdown::gitbook:css: style.csssplit_by: pconfig:toc:collapse: nonebefore: | #設置toc開頭和結尾的鏈接<li><a href="http://www.ehbio.com"><img src="ehbio_logo.png" width="100%"></a></li>after: |<li><a href="mailto:ct@ehbio.com" target="blank">ct@ehbio.com</a></li>download: [pdf, epub, mobi]edit: https://github.com/rstudio/bookdown/edit/master/inst/examples/%ssharing:twitter: nogithub: nofacebook: no

其它定制

  • 不同的文件分別用于html和pdf輸出

    # in _bookdown.yml rmd_files:html: ["index.Rmd", "file2.Rmd"]latex: ["index_pdf.Rmd", "file3.Rmd"]# Different render way #!/bin/sh Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')" Rscript -e "bookdown::render_book('index_pdf.Rmd', 'bookdown::pdf_book')"
  • 配置全局變量自適應HTML和PDF輸出

    ```{r setup, include=FALSE} library(knitr) output <- opts_knit$get("rmarkdown.pandoc.to") html = FALSE latex = FALSE opts_chunk$set(echo = FALSE, fig.align="center", fig.show="hold") if (output=="html") {html = TRUE } if (output=="latex") {opts_chunk$set(out.width="95%", out.height='0.7\\textheight', out.extra='keepaspectratio', fig.pos='H')latex = TRUE } #knitr::opts_chunk$set(cache = FALSE, ?autodep=TRUE) set.seed(0304) ```Below text will only appear in HTML output.```{asis, echo=html}# EHBIO Gene Technology {-}```Below command will only be executed and displayed in HTML output.```{r cover, eval=html, out.width="99%"} knitr::include_graphics("ehbio/cover.png") ``` ~~~~~~~~~~~~~~~~~~~~
  • 保留生成的markdown文件

    # add below lines to last Rmd file ```{r, include=FALSE} file.rename(from="bookdown_file_name.md", ?to="bookdown_file_name.saved.md") ``` ~~~~~~~~~~~
  • 包含子文件 (subfile.txt)

    ```{r child="subfile.txt"} ``` ~~~~~~
  • cahce external file ref

    ```{r mtime-func} mtime <- function(files){lapply(Sys.glob(files), function(x) file.info(x)$mtime) } ``````{r mtime-usage, cache=T, cache.extra=mtime(c("file1", "file2", file3))} file3 <- paste0(dir, '/', name) data1 <- read.table("file1") data2 <- read.table("file2") ``` ~~~

預覽生成的WEB文件

如果沒有安裝Rstudio,可以在生成的book目錄(有index.html的目錄)下運行python -m SimpleHTTPServer 11521 (11521為端口號,一般選較大值避免沖突), 然后就可以在瀏覽器輸入網址http://server-ip:11521來訪問了。

References

  • https://bookdown.org/yihui/bookdown/get-started.html

  • https://github.com/rstudio/bookdown/tree/master/inst/examples

  • http://stackoverflow.com/questions/25236850/how-to-set-different-global-options-in-knitr-and-rstudio-for-word-and-html

  • Multiple output with different configs https://github.com/yihui/knitr/issues/1145

  • Multiple output with different configs https://github.com/yihui/knitr/issues/114://github.com/rstudio/rmarkdown/issues/614

  • Citation style http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html

  • Save markdown http://stackoverflow.com/questions/19989325/knit-rmd-file-to-md-and-save-the-md-file-one-level-up-with-a-different-name

  • PDF online pic http://www.pzhao.org/zh/post/bookdown-tips/

往期精品(點擊圖片直達文字對應教程)

后臺回復“生信寶典福利第一波”或點擊閱讀原文獲取教程合集

總結

以上是生活随笔為你收集整理的别人的电子书,你的电子书,都在bookdown的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 手机在线一区二区三区 | 一个人看的www视频在线观看 | 999精品一区 | 中文av字幕| 毛片手机在线 | 亚洲色图 欧美 | 特黄网站 | 丰满雪白极品少妇流白浆 | 2019天天干| 美女网站免费黄 | 能直接看的av网站 | 超碰在线播放97 | 久久久噜噜噜www成人网 | 国产夫妻性爱视频 | 9色在线视频 | 免费日韩成人 | 亚洲123区 | 中文字幕不卡在线 | 牛牛在线免费视频 | 国产高清一区二区三区四区 | 秋霞一区二区三区 | 亚洲精品三区 | 欧美 唯美 清纯 偷拍 | 日韩电影网站 | 亚洲黄视频| 影音先锋成人资源站 | 色哒哒影院 | 依人成人网 | 天天狠狠操 | 久操视频在线播放 | 黄频在线观看 | 国产视频久久久久久久 | 香港黄色网 | 看av网站| 成人影片网址 | 伊人狼人综合 | 国产免费一区二区三区视频 | 黄色大片av | 亚洲大片免费 | 大胸美女网站 | 欧美在线视频免费观看 | 91精品国产高清一区二区三密臀 | 欧美三级网站 | 欧美日韩黑人 | 国产一区91精品张津瑜 | 色综合中文字幕 | 欧美日韩国产伦理 | 久久精品免费在线观看 | 精品免费观看 | 操校花视频 | 最新视频 - 88av | 18p在线观看 | 少妇熟女高潮流白浆 | 亚洲欧美网站 | 色综合久久久久 | 国产精品综合 | 欧美做爰全过程免费看 | 亚洲第一页在线观看 | 欧洲一级黄色片 | 日韩精品资源 | 激烈娇喘叫1v1高h糙汉 | 天天爽天天摸 | 五月天婷婷基地 | 日韩在线综合 | 亚洲一区二区三区四区视频 | 永久黄网站色视频免费观看w | 午夜精品久久久久久久久久久久 | h片免费网站 | 18色av| 在线日韩视频 | 色戒电影未测减除版 | 欧美a∨亚洲欧美亚洲 | 国产三级国产精品国产专区50 | 欧美精品一区二区三区四区 | 国产精品久久久久久 | 中文字幕久久综合 | 韩国黄色视屏 | 成人欧美一区二区三区白人 | 国产成人无码精品久久 | 红桃视频一区二区三区免费 | 欧美一区二区三区成人精品 | 骚虎视频在线观看 | 操操综合网 | 亚洲爽爽网 | 99久久亚洲精品 | 精品视频久久久久久久 | wwwxxx欧美| 亚洲AV无码成人精品区麻豆 | 久久久网站 | 综合久草 | 亚洲毛片精品 | 美女福利在线视频 | 久久亚洲无码视频 | 日本一区二区三区在线视频 | 色人天堂 | 韩国三色电费2024免费吗怎么看 | 亚洲综合一区中 | 亚洲国产免费看 | 日韩在线播放中文字幕 |