问题描述
R rticles 包写期刊论文爽爽的,只是官方模板的 yaml 设置的输出格式长久以来不支持图表和公式的交叉引用(今天升级到最新版,情况有变化,下面详述)。对此,我用的解决方案是在 .Rmd 文档的 yaml 里将输出格式指定为 bookdown:
output:
rticles::copernicus_article:
base_format: bookdown::pdf_document2
这样,就可以用 bookdown 的方式对图表交叉引用了。
一直这样用,没问题,直到前天或者昨天,在 knitr Rmd 时突然出现了错误:
Error in rmarkdown::pdf_document(..., template = template) :
unused argument (base_format = "bookdown::pdf_document2")
Calls: <Anonymous> ... create_output_format -> do.call -> <Anonymous> -> pdf_document_format
Execution halted
可能是最近我把所有包升了级的缘故?
我忘了上面 base_format 那一行是从哪里学来的了,这回查了 R Markdown 官方文档,蹊跷的是,写法跟我上面的方案是反着的:
output:
bookdown::pdf_document2:
base_format: rticles::peerj_article
按官方文档的格式来,仍然出错:
Error in pdf_book(..., base_format = rmarkdown::pdf_document) :
formal argument "base_format" matched by multiple actual arguments
Calls: <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution halted
于是,今天我把 R 和包括 rticles 在内的所有包都升了级,发现新版的 rticles 包生成的 R Markdown 模板里的 yaml 改成了 bookdown 格式输出,然而跟上述两种写法又不同(我猜这种不同可能是工具链里比如 pandoc 所兼容的):
output:
rticles::copernicus_article: default
bookdown::pdf_book:
base_format: rticles::copernicus_article # for using bookdown features like \@ref()
可是,即使是用升级后的模板,图表的交叉引用仍然不支持。
而且,我回不去了,不知道怎么回到此前好用的版本。
可重现问题的示例文档
下面这个文档,是从 rticles 模板里直接创建后,我把正文部分改成了图的交叉引用。用 RStudio 打开 test.Rmd 然后 ctrl+shift+k 即可。
<https://github.com/pzhaonet/rticles-bookdown>
顺便说一下,我发现这个模板不支持多位通讯作者。这个问题我已在项目主页上提交。
系统环境
> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.9.0 knitr_1.22 magrittr_1.5 R6_2.4.0
[6] tools_3.5.3 pkgbuild_1.0.2 xfun_0.5.2 cli_1.1.0 withr_2.1.2
[11] htmltools_0.3.6 remotes_2.0.2 yaml_2.2.0 digest_0.6.18 assertthat_0.2.0
[16] rprojroot_1.3-2 crayon_1.3.4 bookdown_0.9 processx_3.3.0 callr_3.2.0
[21] ps_1.3.0 curl_3.3 evaluate_0.13 rmarkdown_1.12.2 compiler_3.5.3
[26] backports_1.1.3 rticles_0.7.1 prettyunits_1.0.2