Search code examples
rknitrr-markdowndocxbookdown

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


I am trying to create an article for publication with graphs, tables, cross-referencing and references.

The publishers require the articles to be in docx/doc format.

I have used bookdown::word_document2 and previously had no problem compiling the document.

Suddenly the document has stopped compiling and produces an error.

I have reproduced the problem with an 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)
```

If I include fig.cap="Test caption" I get the following error:

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

If I remove the fig.cap="Test caption", I get the following:

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

Is this a bug or am I doing something wrong?

[EDIT] Here is my 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     

Solution

  • This was because you were using Pandoc 2.0, and bookdown was not fully compatible with this new version of Pandoc yet. I just pushed a fix on Github, and you can install the development version with devtools::install_github("rstudio/bookdown").