XiangyunHuang / ElegantBookdown

:book: A bookdown wrapper for ElegantBook
https://xiangyunhuang.github.io/ElegantBookdown/
Creative Commons Attribution 4.0 International
131 stars 26 forks source link

每章需要独立加载宏包? #19

Closed perlatex closed 3 years ago

perlatex commented 3 years ago

在 index.Rmd 加载的R宏包 ,后面章节用不上呢?比如在index.Rmd

library(tidyverse)
library(palmerpenguins)

而在01-intro.Rmd

penguins %>% 
  head(4) %>% 
  knitr::kable(
    caption = 'Here is a nice table!',
    booktabs = TRUE
)

会报错 Error in penguins %>% head(4) %>% knitr::kable(caption = "Here is a nice table!", : û��"%>%"������� Calls: local ... handle -> withCallingHandlers -> withVisible -> eval -> eval

如果,在01-intro.Rmd 写全却可以

library(tidyverse)
library(palmerpenguins)

penguins %>% 
  head(4) %>% 
  knitr::kable(
    caption = 'Here is a nice table!',
    booktabs = TRUE
)
fyuniv commented 3 years ago

Bookdown 有两个处理方式:merge-knitknit-merge。默认的是 merge-knit。要换成后者,可以在 _boodown.yaml 里添加 new_session: yes 。ElegantBookdown 选择了 knit-merge 的方式。而你想要的应该是默认的方式,所以你可以将 _bookdown.ymal 里的这一行注释掉,或者删除。

perlatex commented 3 years ago

很棒