代码块以交互方式在 R markdown 文件中工作,但当我 "build book" with bookdown 时不行
Code chunk works in R markdown file interactively, but not when I "build book" with bookdown
我正在使用 bookdown 包编写一本电子书。我大约有 31 章,到目前为止几乎没有遇到任何问题。我的一章 Rmd 文件包含以下代码块:
library(dplyr)
set.seed(123)
df <- tibble(
x = rnorm(10),
y = rnorm(10),
z = rnorm(10)
) %>%
print()
df %>%
summarise(
across(
.cols = everything(),
.fns = mean,
.names = "{col}_mean"
)
)
当我 运行 代码块以交互方式进行时,它们会毫无问题地产生预期的结果。但是,当我单击“Build Book”按钮时,出现以下错误:
Quitting from lines 10530-10538 (Book.Rmd)
Error: Problem with `summarise()` input `..1`.
x Problem with `across()` input `.fns`.
ℹ Input `.fns` must be NULL, a function, a formula, or a list of functions/formulas.
ℹ Input `..1` is `across(.cols = everything(), .fns = mean, .names = "{col}_mean")`.
Backtrace:
█
1. ├─rmarkdown::render_site(output_format = "bookdown::gitbook", encoding = "UTF-8")
2. │ └─generator$render(...)
3. │ ├─xfun::in_dir(...)
4. │ └─bookdown:::render_book_script(output_format, envir, quiet)
5. │ └─bookdown::render_book(...)
6. │ └─bookdown:::render_cur_session(...)
7. │ └─rmarkdown::render(...)
8. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
9. │ └─knitr:::process_file(text, output)
10. │ ├─base::withCallingHandlers(...)
11. │ ├─knitr:::process_group(group)
12. │ └─knitr:::process_group.block(gr
Execution halted
Exited with status 1.
这是我的会话信息:
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 bookdown_0.20 tidyr_1.1.0 crayon_1.3.4
[5] digest_0.6.25 dplyr_1.0.1 R6_2.4.1 lifecycle_0.2.0
[9] magrittr_1.5 evaluate_0.14 pillar_1.4.4 rlang_0.4.7
[13] rstudioapi_0.11 ellipsis_0.3.1 vctrs_0.3.2 generics_0.0.2
[17] rmarkdown_2.1 tools_4.0.2 glue_1.4.1 purrr_0.3.4
[21] xfun_0.13 yaml_2.2.1 compiler_4.0.2 pkgconfig_2.0.3
[25] htmltools_0.4.0 tidyselect_1.1.0 knitr_1.28 tibble_3.0.1
有人知道这是怎么回事吗?
如果我设置
mean <- 3
在 运行 你的代码块交互之前,我得到了你看到的错误。您可能在某些较早的代码块中使用 mean
作为变量名。您可以通过将代码编写为
来强制它使用该功能
df %>%
summarise(
across(
.cols = everything(),
.fns = base::mean,
.names = "{col}_mean"
)
)
我正在使用 bookdown 包编写一本电子书。我大约有 31 章,到目前为止几乎没有遇到任何问题。我的一章 Rmd 文件包含以下代码块:
library(dplyr)
set.seed(123)
df <- tibble(
x = rnorm(10),
y = rnorm(10),
z = rnorm(10)
) %>%
print()
df %>%
summarise(
across(
.cols = everything(),
.fns = mean,
.names = "{col}_mean"
)
)
当我 运行 代码块以交互方式进行时,它们会毫无问题地产生预期的结果。但是,当我单击“Build Book”按钮时,出现以下错误:
Quitting from lines 10530-10538 (Book.Rmd)
Error: Problem with `summarise()` input `..1`.
x Problem with `across()` input `.fns`.
ℹ Input `.fns` must be NULL, a function, a formula, or a list of functions/formulas.
ℹ Input `..1` is `across(.cols = everything(), .fns = mean, .names = "{col}_mean")`.
Backtrace:
█
1. ├─rmarkdown::render_site(output_format = "bookdown::gitbook", encoding = "UTF-8")
2. │ └─generator$render(...)
3. │ ├─xfun::in_dir(...)
4. │ └─bookdown:::render_book_script(output_format, envir, quiet)
5. │ └─bookdown::render_book(...)
6. │ └─bookdown:::render_cur_session(...)
7. │ └─rmarkdown::render(...)
8. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
9. │ └─knitr:::process_file(text, output)
10. │ ├─base::withCallingHandlers(...)
11. │ ├─knitr:::process_group(group)
12. │ └─knitr:::process_group.block(gr
Execution halted
Exited with status 1.
这是我的会话信息:
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 bookdown_0.20 tidyr_1.1.0 crayon_1.3.4
[5] digest_0.6.25 dplyr_1.0.1 R6_2.4.1 lifecycle_0.2.0
[9] magrittr_1.5 evaluate_0.14 pillar_1.4.4 rlang_0.4.7
[13] rstudioapi_0.11 ellipsis_0.3.1 vctrs_0.3.2 generics_0.0.2
[17] rmarkdown_2.1 tools_4.0.2 glue_1.4.1 purrr_0.3.4
[21] xfun_0.13 yaml_2.2.1 compiler_4.0.2 pkgconfig_2.0.3
[25] htmltools_0.4.0 tidyselect_1.1.0 knitr_1.28 tibble_3.0.1
有人知道这是怎么回事吗?
如果我设置
mean <- 3
在 运行 你的代码块交互之前,我得到了你看到的错误。您可能在某些较早的代码块中使用 mean
作为变量名。您可以通过将代码编写为
df %>%
summarise(
across(
.cols = everything(),
.fns = base::mean,
.names = "{col}_mean"
)
)