如何加快书本的生成? [英] How to speed up bookdown generation?

查看:62
本文介绍了如何加快书本的生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用书本制作一本书.它使用一些代码段,这些代码段需要花费一些时间来编译,执行和获取输出.我使用以下命令为该书生成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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆