Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add ggsurvplot to powerpoint document using ReporteRs if there is no risk table #314

Closed
DrRZ opened this issue Jun 19, 2018 · 5 comments

Comments

@DrRZ
Copy link

DrRZ commented Jun 19, 2018

Expected behavior

Plot should be added to slide with no error.

Actual behavior

Plot is not added and get the error, "Error in grid.newpage() : pptx device only supports one page". Note, if risk.table = TRUE in the ggsurvplot object, there is no error and the expected behavior occurs.

Steps to reproduce the problem

Create a ggsurvplot object with the risk.table argument set to FALSE and store in variable x. Using the ReporteRs package, create a new slide in a powerpoint document and use the addPlot function to add x to the slide by setting the "fun" argument to function (x) {print(x, newpage = FALSE)}

session_info()

Session info ----------------------------------------------------------------------------------------------------------------------------
setting value
version R version 3.5.0 (2018-04-23)
system x86_64, mingw32
ui Rgui
language (EN)
collate English_Canada.1252
tz America/New_York
date 2018-06-19

Packages --------------------------------------------------------------------------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0)
base * 3.5.0 2018-04-23 local
base64enc 0.1-3 2015-07-28 CRAN (R 3.5.0)
bindr 0.1.1 2018-03-13 CRAN (R 3.5.0)
bindrcpp * 0.2.2 2018-03-29 CRAN (R 3.5.0)
broom 0.4.4 2018-03-29 CRAN (R 3.5.0)
cmprsk 2.2-7 2014-06-17 CRAN (R 3.5.0)
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.0)
compiler 3.5.0 2018-04-23 local
data.table 1.11.4 2018-05-27 CRAN (R 3.5.0)
datasets * 3.5.0 2018-04-23 local
devtools 1.13.5 2018-02-18 CRAN (R 3.5.0)
digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
dplyr 0.7.5 2018-05-19 CRAN (R 3.5.0)
foreign 0.8-70 2017-11-28 CRAN (R 3.5.0)
gdtools * 0.1.7 2018-02-27 CRAN (R 3.5.0)
ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.5.0)
ggpubr * 0.1.6 2017-11-14 CRAN (R 3.5.0)
glue 1.2.0 2017-10-29 CRAN (R 3.5.0)
graphics * 3.5.0 2018-04-23 local
grDevices * 3.5.0 2018-04-23 local
grid 3.5.0 2018-04-23 local
gridExtra 2.3 2017-09-09 CRAN (R 3.5.0)
gtable 0.2.0 2016-02-26 CRAN (R 3.5.0)
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.0)
httpuv 1.4.3 2018-05-10 CRAN (R 3.5.0)
km.ci 0.5-2 2009-08-30 CRAN (R 3.5.0)
KMsurv 0.1-5 2012-12-03 CRAN (R 3.5.0)
knitr 1.20 2018-02-20 CRAN (R 3.5.0)
labeling 0.3 2014-08-23 CRAN (R 3.5.0)
later 0.7.3 2018-06-08 CRAN (R 3.5.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.5.0)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.0)
magrittr * 1.5 2014-11-22 CRAN (R 3.5.0)
Matrix 1.2-14 2018-04-13 CRAN (R 3.5.0)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
methods * 3.5.0 2018-04-23 local
mime 0.5 2016-07-07 CRAN (R 3.5.0)
mnormt 1.5-5 2016-10-15 CRAN (R 3.5.0)
munsell 0.5.0 2018-06-12 CRAN (R 3.5.0)
nlme 3.1-137 2018-04-07 CRAN (R 3.5.0)
officer 0.3.1 2018-06-12 CRAN (R 3.5.0)
parallel 3.5.0 2018-04-23 local
pillar 1.2.3 2018-05-25 CRAN (R 3.5.0)
pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.0)
plyr 1.8.4 2016-06-08 CRAN (R 3.5.0)
png 0.1-7 2013-12-03 CRAN (R 3.5.0)
promises 1.0.1 2018-04-13 CRAN (R 3.5.0)
psych 1.8.4 2018-05-06 CRAN (R 3.5.0)
purrr 0.2.5 2018-05-29 CRAN (R 3.5.0)
R.methodsS3 1.7.1 2016-02-16 CRAN (R 3.5.0)
R.oo 1.22.0 2018-04-22 CRAN (R 3.5.0)
R.utils 2.6.0 2017-11-05 CRAN (R 3.5.0)
R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
Rcpp 0.12.17 2018-05-18 CRAN (R 3.5.0)
ReporteRs * 0.8.10 2018-03-28 CRAN (R 3.5.0)
ReporteRsjars * 0.0.4 2018-03-28 CRAN (R 3.5.0)
reshape2 1.4.3 2017-12-11 CRAN (R 3.5.0)
rJava 0.9-10 2018-05-29 CRAN (R 3.5.0)
rlang 0.2.1 2018-05-30 CRAN (R 3.5.0)
rvg 0.1.9 2018-06-10 CRAN (R 3.5.0)
scales 0.5.0 2017-08-24 CRAN (R 3.5.0)
shiny 1.1.0 2018-05-17 CRAN (R 3.5.0)
splines 3.5.0 2018-04-23 local
stats * 3.5.0 2018-04-23 local
stringi 1.1.7 2018-03-12 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.0)
survival * 2.41-3 2017-04-04 CRAN (R 3.5.0)
survminer * 0.4.2 2018-01-31 CRAN (R 3.5.0)
survMisc 0.5.4 2016-11-23 CRAN (R 3.5.0)
tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
tidyr 0.8.1 2018-05-18 CRAN (R 3.5.0)
tidyselect 0.2.4 2018-02-26 CRAN (R 3.5.0)
tools 3.5.0 2018-04-23 local
utils * 3.5.0 2018-04-23 local
uuid 0.1-2 2015-07-28 CRAN (R 3.5.0)
withr 2.1.2 2018-03-15 CRAN (R 3.5.0)
xml2 1.2.0 2018-01-24 CRAN (R 3.5.0)
xtable 1.8-2 2016-02-05 CRAN (R 3.5.0)
zip 1.0.0 2017-04-25 CRAN (R 3.5.0)
zoo 1.8-2 2018-06-11 CRAN (R 3.5.0)

@kassambara
Copy link
Owner

Fixed now, thanks.

The following R code works:

library(survminer)
library(survival)

fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurv <- ggsurvplot(fit , ggtheme = theme_bw())

library('ReporteRs')
# Create a new powerpoint document
doc <- pptx()
# Add a new slide into the ppt document 
doc <- addSlide(doc, slide.layout = "Two Content"  )
# Add a slide title
doc <- addTitle(doc, "Survival Curves" )
# Print the survival curves in the powerpoint
doc <- addPlot(doc, function() print(ggsurv, newpage = FALSE), 
               vector.graphic = TRUE  # Make it editable
               )
# write the document to a file
writeDoc(doc, file = "survival-curves.pptx")

@christian-rummey
Copy link

were there some changes on this lately?
Your code doesn't work anymore for me, I get again the grid.newpage issue

Error in grid.newpage() : pptx device only supports one page

Any Ideas?

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=English_United States.1252 LC_CTYPE=English_United States.1252 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 grid methods base

other attached packages:
[1] gdtools_0.1.7 survival_2.42-3 survminer_0.4.2 ggpubr_0.1.7 magrittr_1.5 ggplot2_3.0.0 ReporteRs_0.8.10 ReporteRsjars_0.0.4
[9] rJava_0.9-10 gridExtra_2.3

loaded via a namespace (and not attached):
[1] zoo_1.8-3 tidyselect_0.2.4 purrr_0.2.5 splines_3.5.1 lattice_0.20-35 colorspace_1.3-2 htmltools_0.3.6 yaml_2.1.19 base64enc_0.1-3
[10] survMisc_0.5.5 rlang_0.2.1 later_0.7.3 R.oo_1.22.0 pillar_1.3.0 withr_2.1.2 R.utils_2.6.0 glue_1.3.0 bindrcpp_0.2.2
[19] uuid_0.1-2 bindr_0.1.1 plyr_1.8.4 munsell_0.5.0 gtable_0.2.0 R.methodsS3_1.7.1 zip_1.0.0 labeling_0.3 knitr_1.20
[28] httpuv_1.4.5 broom_0.5.0 Rcpp_0.12.18 xtable_1.8-2 promises_1.0.1 backports_1.1.2 scales_0.5.0 cmprsk_2.2-7 mime_0.5
[37] km.ci_0.5-2 png_0.1-7 digest_0.6.15 shiny_1.1.0 dplyr_0.7.6 KMsurv_0.1-5 tools_3.5.1 lazyeval_0.2.1 tibble_1.4.2
[46] crayon_1.3.4 tidyr_0.8.1 pkgconfig_2.0.1 Matrix_1.2-14 data.table_1.11.4 xml2_1.2.0 rvg_0.1.9 assertthat_0.2.0 officer_0.3.2
[55] rstudioapi_0.7 R6_2.2.2 nlme_3.1-137 compiler_3.5.1

@kassambara
Copy link
Owner

The code still work for me. Make sure to specify the argument newpage = FALSE in print()

@shitiezhu
Copy link

ReporteRs was rewrited to officer package, ggsurvplot object of class "c('ggsurvplot', 'ggsurv', 'list') still can not export to pptx file in officer package. Need to be solved!!! Thank you!

@shitiezhu
Copy link

And the ReporteRs package is now not avalible for 3.6.0 version R.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants