Bookdown - 在哪里加载包
Bookdown - where to load packages
我有一个大型 bookdown 项目,我想检查其中一章是否有效。
我已经写好了,所以我需要的所有包都在 Index.Rmd
中加载
然而,当我尝试渲染这本书或预览一章时,它失败了,因为找不到函数 %>%
,即使 library(dplyr)
在 Index.Rmd 中。
是否真的有必要在 bookdown 项目的每一章开头加载相同的包?还是我遗漏了什么?
Is it really necessary to load the same packages
at the start of each chapter in a bookdown project?
这取决于你的 knitr 方法:
Merging all chapters into one Rmd file and knitting it is one way to render the book in bookdown. There is actually another way: you may knit each chapter in a separate R session, and bookdown will merge the Markdown output of all chapters to render the book. We call these two approaches “Merge and Knit” (M-K) and “Knit and Merge” (K-M), respectively. …
M-K runs all code chunks in all chapters in the same R session, whereas K-M uses separate R sessions for individual chapters. For M-K, the state of the R session from previous chapters is carried over to later chapters (e.g., objects created in previous chapters are available to later chapters, unless you deliberately deleted them); for K-M, all chapters are isolated from each other.
如果您不想加载库,您也可以使用 ::
符号引用该函数,例如knitr::kable(head(iris, 20))
已添加:有关如何继续的更多信息,请查看 bookdown manual。
我有一个大型 bookdown 项目,我想检查其中一章是否有效。 我已经写好了,所以我需要的所有包都在 Index.Rmd
中加载然而,当我尝试渲染这本书或预览一章时,它失败了,因为找不到函数 %>%
,即使 library(dplyr)
在 Index.Rmd 中。
是否真的有必要在 bookdown 项目的每一章开头加载相同的包?还是我遗漏了什么?
Is it really necessary to load the same packages
at the start of each chapter in a bookdown project?
这取决于你的 knitr 方法:
Merging all chapters into one Rmd file and knitting it is one way to render the book in bookdown. There is actually another way: you may knit each chapter in a separate R session, and bookdown will merge the Markdown output of all chapters to render the book. We call these two approaches “Merge and Knit” (M-K) and “Knit and Merge” (K-M), respectively. …
M-K runs all code chunks in all chapters in the same R session, whereas K-M uses separate R sessions for individual chapters. For M-K, the state of the R session from previous chapters is carried over to later chapters (e.g., objects created in previous chapters are available to later chapters, unless you deliberately deleted them); for K-M, all chapters are isolated from each other.
如果您不想加载库,您也可以使用 ::
符号引用该函数,例如knitr::kable(head(iris, 20))
已添加:有关如何继续的更多信息,请查看 bookdown manual。