1

Minimum Reproducible example of my R notebook (.Rmd) file which causes the error while knitting to word document:

---
title: "R Notebook"
output: bookdown::word_document2
---

Using inline R code chunks with `officer::ftext` causes an error as such


`r officer::ftext('Example text', officer::fp_text(color = 'red'))`

The error when knitting is as follows:

Error in vapply(x, format_sci_one, character(1L), ..., USE.NAMES = FALSE) : values must be length 1, but FUN(X[[2]]) results in length 8 Calls: <Anonymous> ... paste -> hook -> .inline.hook -> formact_sci -> vapply

This error started occurring only recently. Previously with this code, I was able to output a word document where the inline code chunk would produce text 'Example text' with red font color.

My .SessionInfo() output is:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252    LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C                       
[5] LC_TIME=German_Switzerland.1252    

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

other attached packages:
[1] ROracle_1.3-1.1 DBI_1.1.2      

loaded via a namespace (and not attached):
 [1] compiler_3.5.1  bookdown_0.24   fastmap_1.1.0   htmltools_0.5.2 tools_3.5.1     yaml_2.2.1      rmarkdown_2.11  knitr_1.37      xfun_0.29       digest_0.6.29  
[11] rlang_0.4.12    evaluate_0.14  

I'm using Pandoc 2.1. Please note that I'm using this R setup at work, so I'm not able to update to a newer version of R or RStudio IDE.

Naeem Khoshnevis
  • 2,001
  • 4
  • 18
  • 30
  • Can confirm the bug is also present in R 4.1.2 and Rstudio desktop (I'm also on Ubuntu, so not an issue of OS). – csgroen Jan 10 '22 at 13:15
  • Updating sessionInfo() outtput after loading packages used in the working R Notebook. For some reason I cannot edit my question so I'm posting it in the comments – VBAEnthusiast Jan 10 '22 at 14:12
  • `other attached packages: [1] ftExtra_0.0.3 flextable_0.5.10 officer_0.3.11 bookdown_0.24 knitr_1.37 rmarkdown_2.11 mgsub_1.7.3 lubridate_1.8.0 readxl_1.3.1 [10] data.table_1.14.2 scales_1.1.1 ggplot2_3.3.5 tidyr_1.1.4 dplyr_1.0.7 ROracle_1.3-1.1 DBI_1.1.2 ` – VBAEnthusiast Jan 10 '22 at 14:12
  • `loaded via a namespace (and not attached): [1] zip_2.0.3 Rcpp_1.0.7 pillar_1.6.4 compiler_3.5.1 cellranger_1.1.0 base64enc_0.1-3 tools_3.5.1 uuid_1.0-3 digest_0.6.29 [10] evaluate_0.14 lifecycle_1.0.1 tibble_3.1.6 gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.12 yaml_2.2.1 xfun_0.29 fastmap_1.1.0 [19] xml2_1.3.3 withr_2.4.3 systemfonts_1.0.3 gdtools_0.2.3 generics_0.1.1 vctrs_0.3.8 grid_3.5.1 tidyselect_1.1.1 glue_1.6.0 ...` – VBAEnthusiast Jan 10 '22 at 14:13
  • `... [28] R6_2.5.1 fansi_0.5.0 purrr_0.3.4 magrittr_2.0.1 ellipsis_0.3.2 htmltools_0.5.2 colorspace_2.0-2 utf8_1.2.2 munsell_0.5.0 [37] crayon_1.4.2` – VBAEnthusiast Jan 10 '22 at 14:13

1 Answers1

1

The .Rmd file started knitting properly to word after I installed and loaded package officedown version 0.1.0. I initially tried with version 0.2.0, but then if I used non-alphanumeric characters as text input in officer::ftext function (eg. '%', '[') in the word output it appeared as an xml structure instead of formatted text.

Credit goes to David Gohel, developer of the officer packages who pointed me to the officedown package, see discussion on his github page: https://github.com/davidgohel/officer/issues/402