fig.caption 使用 bookdown::word_document2 时停止 r markdown 到 docx

fig.caption stops r markdown to docx when using bookdown::word_document2

我正在尝试创建一篇包含图表、表格、交叉引用和参考文献的文章。

出版商要求文章采用 docx/doc 格式。

我用过bookdown::word_document2,之前编译文档没问题

文档突然停止编译并产生错误。

我已经用 MWE 重现了这个问题:

---
title: "MWE"
author: "JEB"
date: "13th November 2017"
output:
    bookdown::word_document2:
      fig_caption: true
---

## Including Plots

You can also embed plots, for example \@ref(fig:pressure)

```{r pressure, echo=FALSE, fig.cap="Test caption"}
plot(pressure)
```

如果我包含 fig.cap="Test caption",我会收到以下错误:

Error in parse_fig_labels(x, global) : There are multiple labels on one line: (#fig:pressure), (#fig:pressure) Calls: ... -> process_markdown -> parse_fig_labels Execution halted

如果我删除 fig.cap="Test caption",我会得到以下信息:

Output created: test.docx Warning message: The label(s) fig:pressure not found

这是一个错误还是我做错了什么?

[编辑] 这是我的 sessionInfo()

sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS: /usr/lib/libblas.so.3.7.1
LAPACK: /usr/lib/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               
LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8    
LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             
LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2        ez_4.4-0            knitr_1.17          
reshape2_1.4.2      pastecs_1.3-18     
 [6] boot_1.3-20         car_2.1-5           compute.es_0.2-4    
gridExtra_2.3       ggplot2_2.2.1      
[11] xtable_1.8-2        data.table_1.10.4-3 dplyr_0.7.4        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13       highr_0.6          compiler_3.4.2     nloptr_1.0.4       plyr_1.8.4        
 [6] bindr_0.1          tools_3.4.2        digest_0.6.12      lme4_1.1-14        evaluate_0.10.1   
[11] tibble_1.3.4       gtable_0.2.0       nlme_3.1-131       lattice_0.20-35    mgcv_1.8-22       
[16] pkgconfig_2.0.1    rlang_0.1.4        Matrix_1.2-11      yaml_2.1.14        parallel_3.4.2    
[21] SparseM_1.77       stringr_1.2.0      MatrixModels_0.4-1 rprojroot_1.2      nnet_7.3-12       
[26] glue_1.2.0         R6_2.2.2           bookdown_0.5       rmarkdown_1.7      minqa_1.2.4       
[31] magrittr_1.5       backports_1.1.1    htmltools_0.3.6    scales_0.5.0       MASS_7.3-47       
[36] splines_3.4.2      assertthat_0.2.0   pbkrtest_0.4-7     colorspace_1.3-2   labeling_0.3      
[41] quantreg_5.34      stringi_1.1.5      lazyeval_0.2.1     munsell_0.4.3     

这是因为您使用的是 Pandoc 2.0,而 bookdown 还不完全兼容这个新版本的 Pandoc。我刚刚用 devtools::install_github("rstudio/bookdown").

推送了 a fix on Github, and you can install the development version