【问题标题】:flextable and officedown error: read_docx only support docx filesflextable 和 officedown 错误:read_docx 仅支持 docx 文件
【发布时间】:2020-10-01 15:15:41
【问题描述】:

flextable 和 officedown 产生错误:read_docx only support docx files 出现在使用 officedown 的最小尝试中。我见过这个post,但我的文件路径没有空格,所以这似乎不是问题。

---
date: "`r Sys.Date()`"
author: "Your Name"
title: "officedown template"
output: 
  officedown::rdocx_document:
    mapstyles:
      Normal: ['First Paragraph']
---

knitr::opts_chunk$set(echo = TRUE, fig.cap = TRUE)
library(officedown)
library(officer)
library(flextable)

fp <- fp_par(
  text.align = "center", 
  padding.bottom = 20, padding.top = 120, 
  border.bottom = fp_border())

ft <- fp_text(shading.color='#EFEFEF', bold = TRUE)

flextable(mtcars)
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

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     

other attached packages:
[1] shiny_1.4.0.2        flextable_0.6.0.002  officer_0.3.14       officedown_0.2.1.001

loaded via a namespace (and not attached):
 [1] xfun_0.17         remotes_2.1.1     testthat_2.3.2    miniUI_0.1.1.1    htmltools_0.5.0  
 [6] usethis_1.6.1     yaml_2.2.1        base64enc_0.1-3   rlang_0.4.7       pkgbuild_1.0.8   
[11] later_1.1.0.1     glue_1.4.2        withr_2.2.0       gdtools_0.2.2     sessioninfo_1.1.1
[16] uuid_0.1-4        zip_2.1.1         devtools_2.3.0    memoise_1.1.0     evaluate_0.14    
[21] knitr_1.30        callr_3.4.3       fastmap_1.0.1     httpuv_1.5.4      ps_1.3.3         
[26] fansi_0.4.1       Rcpp_1.0.5        xtable_1.8-4      promises_1.1.1    backports_1.1.7  
[31] desc_1.2.0        pkgload_1.1.0     jsonlite_1.7.1    mime_0.9          systemfonts_0.3.2
[36] fs_1.4.1          digest_0.6.25     processx_3.4.2    rprojroot_1.3-2   here_0.1         
[41] cli_2.0.2         tools_4.0.2       magrittr_1.5      whisker_0.4       crayon_1.3.4     
[46] ellipsis_0.3.1    data.table_1.12.8 xml2_1.3.2        prettyunits_1.1.1 rvg_0.2.5        
[51] reprex_0.3.0      assertthat_0.2.1  rmarkdown_2.4     rstudioapi_0.11   R6_2.4.1         
[56] compiler_4.0.2 

【问题讨论】:

  • 很遗憾,我无法重现您的错误。你的 Rmd 在我的机器上渲染得很好。我尝试了 flextable 和 officedown 的 CRAN 版本以及您正在使用的开发版本。
  • 这是第三次有人报告,我仍然无法确定问题(我希望能够重现它以便我可以解决它)。您是否还可以添加有关 rmd 文件路径的信息以及.libPaths()。这可能会有所帮助...
  • 嗨大卫,RMD 文件的路径是:C:\Users\myusername\Desktop\Check\test_officdown_v2.Rmd .libPaths() 返回“C:/Program Files/R/R-4.0. 2/图书馆”

标签: r r-markdown flextable


【解决方案1】:

您好 Jessica 和 David Gohel,

我看到this post 在使用flextable 时出现关于read_docx 的相同错误。基于 Mike M 的巨大努力,问题很可能来自 文件路径

我已经解决了我的问题,因为我终于在我的用户名中找到了一个空格,所以 officedown 生成的模板文件路径将被复制到C:\Users\Myfirstname Mygivenname\AppData\something_else。然后在终端中它将是C:\Users\Myfirstname~Mygivenname\AppData\something_else 并出错。这可能是 Windows 用户的问题,因为我在我的 Mac 上尝试过同样的事情并且它有效。

所以请确保您的用户名(或整个文件路径)没有空格

感谢 David 提供 officedown 包和 Mike M 的工作。

【讨论】:

    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 2012-06-15
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    相关资源
    最近更新 更多