【问题标题】:fig.caption stops r markdown to docx when using bookdown::word_document2fig.caption 在使用 bookdown::word_document2 时停止 r markdown 到 docx
【发布时间】:2017-11-13 09:09:19
【问题描述】:

我正在尝试创建一篇带有图表、表格、交叉引用和参考的文章以供发布。

出版商要求文章为 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",则会收到以下错误:

parse_fig_labels(x, global) 中的错误: 一行中有多个标签:(#fig:pressure), (#fig:pressure) 调用:... -> process_markdown -> parse_fig_labels 执行停止

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

创建的输出:test.docx 警告信息: 标签图:未找到压力

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

[编辑] 这是我的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     

【问题讨论】:

  • 我无法重现您的错误。你的例子对我来说很好。也许更新你所有的图书馆?
  • @J_F 我已经更新了它们,那是编译过程停止工作的时候。这就是为什么我想知道它是否是一个错误。我将编辑问题以包含我的session.info()
  • 一些附加信息:1.)如果我在 yaml 中使用fig_caption: false,那么文档编译没有问题,2.)更新到 bookdown 的开发版本(0.5.8)没有帮助.
  • 已将此作为问题提交到 github 页面上以供预订 https://github.com/rstudio/bookdown/issues/483
  • 在 YAML 中没有 site: bookdown::bookdown_site 就无法构建。

标签: r knitr r-markdown docx bookdown


【解决方案1】:

这是因为您使用的是 Pandoc 2.0,而 bookdown 尚未与此新版本的 Pandoc 完全兼容。我刚刚在 Github 上推了a fix,你可以安装the development versiondevtools::install_github("rstudio/bookdown")

【讨论】:

  • 感谢您的及时修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 2021-12-03
  • 1970-01-01
  • 2020-12-19
  • 1970-01-01
  • 2014-06-18
  • 2020-04-27
相关资源
最近更新 更多