作者:Yihui Xie
译者:郑宝童
日期:2021.05.14


1.2 Get started

The easiest way for beginners to get started with writing a book with R Markdown and bookdown is through the demo bookdown-demo on GitHub:

  1. Download the GitHub repository https://github.com/rstudio/bookdown-demo as a Zip file, then unzip it locally.
  2. Install the RStudio IDE. Note that you need a version higher than 1.0.0. Please download the latest version if your RStudio version is lower than 1.0.0.
  3. Install the R package bookdown:
  1. # stable version on CRAN
  2. install.packages("bookdown")
  3. # or development version on GitHub
  4. # remotes::install_github('rstudio/bookdown')
  1. Open the bookdown-demo repository you downloaded in RStudio by clicking bookdown-demo.Rproj.
  2. Open the R Markdown file index.Rmd and click the button Build Book on the Build tab of RStudio.

对于初学者来说,使用R Markdown和bookdown开始写书的最简单的方法是通过GitHub上的示例bookdown-demo:

  1. 以Zip文件的形式下载GitHub仓库https://github.com/rstudio/bookdown-demo,然后在本地解压缩。
  2. 安装RStudio IDE。注意,您需要一个高于1.0.0的版本。如果RStudio版本低于1.0.0,请下载最新版本( download the latest version)。
  3. 安装R包bookdown

    1. # stable version on CRAN
    2. install.packages("bookdown")
    3. # or development version on GitHub
    4. # remotes::install_github('rstudio/bookdown')
  4. 点击bookdown-demo.Rproj,打开RStudio中下载的 bookdown-demo 库。

  5. 打开R Markdown文件index.Rmd。然后单击RStudio Build 选项卡上的Build Book按钮。

If you are planning on printing your book to PDF, you will need a LaTeX distribution. We recommend that you install TinyTeX (which includes XeLaTeX): https://yihui.org/tinytex/.

如果你打算把你的书导出成PDF,你需要一个LaTeX发行版。我们建议您安装TinyTeX(它包含了XeLaTeX): https://yihui.org/tinytex/。

Now you should see the index page of this book demo in the RStudio Viewer. You may add or change the R Markdown files, and hit the Knit button again to preview the book. If you prefer not to use RStudio, you may also compile the book through the command line. See the next section for details.

现在你应该在RStudio查看器中看到这本书演示的索引页。您可以添加或更改R Markdown文件,并再次点击Knit 按钮来预览这本书。如果你不喜欢使用RStudio,你也可以通过命令行编译这本书。有关详细信息,请参见下一节。

Although you see quite a few files in the bookdown-demo example, most of them are not essential to a book. If you feel overwhelmed by the number of files, you can use this minimal example instead, which is essentially one file index.Rmd: https://github.com/yihui/bookdown-minimal. The bookdown-demo example contains some advanced settings that you may want to learn later, such as how to customize the LaTeX preamble, tweak the CSS, and build the book on GitHub, etc.

尽管您在bookdown演示示例中看到了相当多的文件,但它们中的大多数对一本书来说并不是必需的。如果您觉得文件太多,那么可以使用这个最小的示例,它实际上是一个文件索引。限制型心肌病:https://github.com/yihui/bookdown-minimal。这个book - down-demo示例包含了一些你以后可能想要学习的高级设置,比如如何自定义LaTeX序言,调整CSS,以及如何在GitHub上构建这本书,等等。