1

I'm new to officedown. I'm currently reviewing it to see if the company wants to use it in production. I'm having problems producing output from one of their examples: minimal_word.Rmd. Weirdly, I am able to run all their other examples (also in github) with no issues, so this is puzzling me, as they have similar settings and uses. I thought it might be a package missing or something, but my guess is that then the other examples would also crash and they don't.

I've tried to locate which parts of the code are causing my issue to try to create a minimal-minimal example to add here:

---
title: "officedown example"
output:
  officedown::rdocx_document
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, fig.cap = TRUE)
library(officedown)
```

## Table

```{r tab.cap="caption 1", tab.id="mtcars"}
#head(mtcars)                             ### produces error
#head(data.frame(x=1:10,y=LETTERS[1:10])) ### produces error
head(1:10)                                ### runs ok
```

The original code has some table of contents and some sections that compile ok when on their own. Issues start with their Tables section. Example code has the head(mtcars) line: doesn't work, then I tried to simplify it first by taking out the dependency to cars with a simple data.frame: doesn't work. When I simplify to a vector, then it works and produces word document(!?).

I'm thinking it should be a silly thing on my part, but cannot nail it.

Any help?

rmarkdown::render full output:

processing file: minimal_word2.Rmd
  |.........                                                             |  12%
  ordinary text without R code

  |..................                                                    |  25%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |..........................                                            |  38%
  ordinary text without R code

  |...................................                                   |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ tab.cap: chr "caption 1"
 $ tab.id : chr "mtcars"

  |............................................                          |  62%
  ordinary text without R code

  |....................................................                  |  75%
label: unnamed-chunk-2 (with options) 
List of 1
 $ fig.cap: chr "figure caption"


Quitting from lines 23-24 (minimal_word2.Rmd) 
Error: read_docx only support docx files

and sessionInfo():

R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Mexico.1252  LC_CTYPE=Spanish_Mexico.1252    LC_MONETARY=Spanish_Mexico.1252
[4] LC_NUMERIC=C                    LC_TIME=Spanish_Mexico.1252    

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

other attached packages:
[1] officer_0.3.12   officedown_0.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      digest_0.6.25     R6_2.4.1          magrittr_1.5      evaluate_0.14    
 [6] zip_2.0.4         gdtools_0.2.2     rlang_0.4.6       uuid_0.1-4        xml2_1.3.2       
[11] rmarkdown_2.3     tools_3.6.3       xfun_0.15         yaml_2.2.1        compiler_3.6.3   
[16] systemfonts_0.2.3 rvg_0.2.5         memoise_1.1.0     htmltools_0.5.0   knitr_1.29 
AMM
  • 21
  • 3
  • Could you clarify what means "doesn't work"? Do you get an error message, if yes, what is it? Your Word document is said "corrupted" by Word? Also could you add your sessionInfo() – David Gohel Jul 13 '20 at 18:31
  • Sorry, should have added it explicitlyand not only on title. I'm getting an error in the Rmarkdown tab : "Error: read_docx only support docx files" – AMM Jul 15 '20 at 22:44
  • Could you use `rmarkdown::render` so that we can read the whole trace and also provide results of `sessionInfo()`? – David Gohel Jul 16 '20 at 07:34
  • Yes , thanks, I've added those in the (edited) question – AMM Jul 17 '20 at 13:55
  • thanks! Do you have any accent in your working directory (like french sometimes have é, à, ç, etc.)? That could be a reason (this is solved in the dev version of officer but not on cran yett). Sorry for all the questions, It is difficult to reproduce. – David Gohel Jul 17 '20 at 20:26
  • No, no weird symbols in path... Sorry it is difficult to reproduce. I'll try on another machine. Weird thing is that all the other Rmd examples provided in the package work well. Stored in same directory. It is just this that fails. Thanks for trying to help. – AMM Jul 20 '20 at 21:31

1 Answers1

0

I ran into what might be the same thing.
I was starting from flextable, which is by the same developer, and which consumes officer.

In the end...

  • it was that the package does not allow spaces in file paths

Here is my final result after a long slog through it...
https://stackoverflow.com/a/63652181/1518460

If you are still addressing this issue, maybe give a try making sure all your paths are without spaces,
starting with any reference_docx (my issue)
and also any output path (maybe project folder or working folder or explicit output path).

If you have time to try it, let me know if it works!
(and we'll both chase the developer :-) . . . I'm sure they want to fix it)

Mike M
  • 1,382
  • 11
  • 23
  • Thanks for your answer. I checked but apart from some windows folders that have spaces, all is ok qith no spaces or weird characters.... In fact, I dont think in my case it is that... The same Rmd file in the same folder, renders ok if I only try to render a table with, e.g., head(1:10) ... but breaks when I try to render e.g. head(data.frame(x=1:10,y=LETTERS[1:10])) .... it is very puzzling... cant really appreciate the difference of trying to render a dataframe or a vector... – AMM Sep 07 '20 at 16:21
  • both are during Knit? just to check..... not a matter of Console vs Viewer – Mike M Sep 07 '20 at 18:59