3

我想使用模板自动创建 powerpoint 报告。根据 ReporteRs 文档,这是通过以下方式完成的:

doc = pptx(template = '/path/to/template.pptx')

即使尝试加载最简单的模板,我也会收到以下错误:

Error in pptx(template = '/path/to/template.pptx') : 
  an error occured - code[LOADDOC_ERROR].

即使是 ReporteRs 的 CRAN 参考中的最小示例也会导致我出错。这是pdf参考,下面是第86页的示例。他们首先创建了一个名为“template_example.pptx”的简单模板,然后加载模板,并对幻灯片进行了小改动。我可以毫无错误地创建模板,但是一旦我尝试加载新模板,就会收到前面提到的错误。

# create an doc to be used as template later
mydoc = pptx( )
mydoc = addSlide( mydoc, slide.layout = "Title and Content")
mydoc = addTitle( mydoc, "a table")
mydoc = addFlexTable( mydoc, ft1 )
mydoc = addSlide( mydoc, slide.layout = "Title and Content")
mydoc = addTitle( mydoc, "some text")
mydoc = addParagraph( mydoc, "text example" )
writeDoc( mydoc, "template_example.pptx" )

# use file pp_template_example.pptx as template
# and replace slide 1
mydoc = pptx(template = "template_example.pptx" )
mydoc = addSlide( mydoc, slide.layout = "Title and Content", bookmark = 1)
mydoc = addTitle( mydoc, "a new table")
mydoc = addFlexTable( mydoc, ft2 )
writeDoc( mydoc, "slide_replacement.pptx" )

有没有人知道为什么会发生这个错误?谢谢。

编辑:添加SessionInfo()输出。

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] ggplot2_1.0.1        lubridate_1.3.3      DT_0.1               readr_0.2.2          dplyr_0.4.3          shinydashboard_0.5.1
[7] rga_0.8              httr_1.0.0           jsonlite_0.9.16      RCurl_1.95-4.7       bitops_1.0-6         openxlsx_3.0.0      
[13] shiny_0.12.2         RAdwords_0.1.6       rJava_0.9-7          ReporteRs_0.8.2      ReporteRsjars_0.0.2 

loaded via a namespace (and not attached):
[1] Rcpp_0.11.6      plyr_1.8.3       tools_3.2.2      digest_0.6.8     memoise_0.2.1    gtable_0.1.2     DBI_0.3.1        rstudioapi_0.3.1
[9] yaml_2.1.13      parallel_3.2.2   proto_0.3-10     stringr_1.0.0    htmlwidgets_0.5  grid_3.2.2       R6_2.1.1         reshape2_1.4.1  
[17] magrittr_1.5     scales_0.2.5     htmltools_0.2.6  MASS_7.3-43      assertthat_0.1   mime_0.3         colorspace_1.2-6 xtable_1.7-4    
[25] httpuv_1.3.3     labeling_0.3     stringi_0.5-5    lazyeval_0.1.10  munsell_0.4.2    rjson_0.2.15 
4

1 回答 1

2

In case anyone has this issue, follow @David Gohel's advice --> https://github.com/davidgohel/ReporteRs/issues/101

davidgohel commented on Dec 23, 2015 OK,

it seems the bug is about how we expressed the filename. This works:

pptx(template = "/Users/xxxx/Downloads/doc.pptx")

But this failed:

pptx(template = "~/Downloads/doc.pptx")
于 2016-04-15T22:25:44.480 回答