如何加快书本的生成? [英] How to speed up bookdown generation?
问题描述
我目前正在使用书本制作一本书.它使用一些代码段,这些代码段需要花费一些时间来编译,执行和获取输出.我使用以下命令为该书生成HTML,PDF和EPUB文件:
I'm currently working on a book using bookdown. It uses some code snippets which take time to compile, execute and get output. I use the following commands to build HTML, PDF and EPUB files for the book:
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book')"
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::epub_book')"
因此,每次生成图书文件时,都会进行实际计算,从而增加了总生成时间×3.
So, every time the book files are generated the actual computation takes place increasing the overall generation time ×3.
有什么方法可以在初次运行时生成一些中间文件,而不用它来构建HTML,PDF和EPUB输出?
Is there any way to produce some intermediate file on the first run and than use it to build HTML, PDF and EPUB outputs?
推荐答案
我设法通过将以下代码段添加到我的index.Rmd
中来显着减少了再生时间:
I managed to significantly reduce the regeneration time by adding the following snippet to my index.Rmd
:
```{r include=FALSE}
knitr::opts_chunk$set(cache = TRUE)
```
更新:
以 Yuriy Barvinchenko 和仅缓存耗时的代码块:
As Yuriy Barvinchenko and Yihui Xie both suggested, it's better to cache only time-consuming code chunks:
```{go time-sleep-demo cache = TRUE}
package main
import (
"fmt"
"time"
)
func main() {
fmt.Print("Hello ")
time.Sleep(10 * time.Second)
fmt.Println("world!")
}
```
这篇关于如何加快书本的生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!