flextable and officedown error: read_docx only support docx files

336 views Asked by At

flextable and officedown produces an error: read_docx only support docx files appears in minimial attempt at using officedown. I have seen this post, but my file path has no spaces so that does not appear to be the issue.

---
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 
1

There are 1 answers

0
Shun Bi On

Hi Jessica and David Gohel,

I saw this post that had the same error about read_docx when using flextable. Based on the great effort by Mike M, the problem is most possibly from the filepath!

I have fixed my problem because I finally found a space in my username so the filepath of templated generated by officedown will be copied to C:\Users\Myfirstname Mygivenname\AppData\something_else. Then in terminal it will be C:\Users\Myfirstname~Mygivenname\AppData\something_else and get wrong. This is may be the question for Windows users as I have tried the same thing on my Mac and it works.

So make sure that your username (or the entire filepath) does not have any space!

Thanks David for officedown package and the work by Mike M.