When I'm opening a docx file generated by R
package officer
which is inserted with a tiff picture file, the Office 2016 throw me an error massage.
example:
library(magrittr)
library(ggplot2)
library(officer)
img <- "test.tiff"
pic <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
img %>% ggsave(pic, width = 6, height = 3)
read_docx() %>%
body_add_img(img, width = 6, height = 3) %>%
print(target = "test.docx")
Then when opening test.docx
, I got an error massage
We're sorry. We can't open test.docx because we found a problem with its contents.
Details
The file is corrupt and cannot be opened.
After I press 'OK' button, Word ask me if I want to recover the contents of the document. Choose 'yes' then I got a Document1 with correct picture in it.
I tried .jpg and .png format, and they both worked correctly, so this can be a work-around for now. Is this a bug or just me making mistakes? Either way it is truly welcomed to enlighten me, thanks.
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] officer_0.2.0 ggplot2_2.2.1 magrittr_1.5
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 digest_0.6.13 R.methodsS3_1.7.1 R6_2.2.2 grid_3.4.3
[6] plyr_1.8.4 gtable_0.2.0 scales_0.5.0 zip_1.0.0 rlang_0.1.6
[11] uuid_0.1-2 lazyeval_0.2.1 R.oo_1.21.0 R.utils_2.6.0 xml2_1.1.1
[16] labeling_0.3 tools_3.4.3 munsell_0.4.3 yaml_2.1.16 compiler_3.4.3
[21] base64enc_0.1-3 colorspace_1.3-2 htmltools_0.3.6 tibble_1.3.4