davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
245 stars 44 forks source link

complete section in one page #185

Closed shashi108 closed 7 years ago

shashi108 commented 7 years ago

How one complete section comes in one page,either in page 1 or 2,i shown one example in picture? this thime Month 3 factor comes in page 1 and 2,but i want in comes in page 1 or 2? ffe

`#%%%%%%%%%%%%%%%%%%%% Export in word %%%%%%%%%%%%%
library(ReporteRsjars) library(ReporteRs)

Create a word document to contain R outputs

doc <- docx(template=paste(path_temp,"Template_table 3.docx",sep="/"))

options( "ReporteRs-fontsize" = 9, "ReporteRs-default-font" = "Courier")

Add a title to the document x=table no,y=baseline day,z=table

par_fun<-function(x,y,z){ Title_t2<-pot(paste("Table" ,x,"Change in UEMS from Baseline by AIS/NLI- Change from Baseline ",y,"days")) MyFTable <-FlexTable(data=z,header.columns = F)

doc = addPageBreak(doc )

MyFTable <- addHeaderRow( MyFTable, value ="Table 3.1 Change in UEMS from Baseline by AIS/NLI- Change from Baseline 0 to 3 Days \n Population: EMSCI Database (Version January, 2016) \n \n",

                        colspan = c(11),first = FALSE)

MyFTable <- addHeaderRow( MyFTable,

value = c("-"),colspan = c(11) )

MyFTable <- addHeaderRow( MyFTable, value = c("Timepoint", "A", "B","C","D","Total"), colspan = c(1, 2, 2, 2,2,2) ) MyFTable <- addHeaderRow( MyFTable, value = c( "", paste("(N=",N_A,")",sep=""),paste("(N=",N_B,")",sep="") ,paste("(N=",N_C,")",sep=""),paste("(N=",N_D,")",sep=""), paste("(N=",N_Tot,")",sep="")), colspan = c(1, 2, 2, 2,2,2) ) MyFTable <- addHeaderRow( MyFTable, value = c( "", "Actual","Change","Actual","Change","Actual","Change","Actual","Change","Actual","Change"), colspan = c(rep(1,11)) )

border properties to use later

no_border = borderProperties( width = 0 ) big_border = borderProperties( width = 2 ) std_border = borderProperties( width = 1 )

another_border = borderProperties(width = 2, color = "red", style = "dashed")

format the table grid borders

MyFTable = setFlexTableBorders( MyFTable, inner.vertical = no_border, inner.horizontal = no_border, outer.vertical = no_border, outer.horizontal = big_border ) MyFTable[2,1:11, to="header"] = big_border MyFTable[1,1:11, to="header"] = no_border

MyFTable<-setFlexTableWidths(MyFTable,widths = c(1,rep(0.9,length(colnames(z))-1))) MyFTable[ to = "header" ] = textBold() MyFTable[ to = "header" ] = parCenter() MyFTable[ , 1 ] = parProperties( text.align = "left" ) MyFTable[ , 2:length(colnames(z))] = parProperties( text.align = "center" ) doc <- addFlexTable( doc, MyFTable,par.properties = parProperties(text.align = "center")) setwd(result_path) writeDoc(doc, file = "Table3.1_EMSCI.docx") } par_fun("3.1","0-3",Table3) > sessionInfo() R version 3.3.3 (2017-03-06) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages: [1] Publish_1.2.3 devtools_1.12.0 prodlim_1.6.1 ReporteRs_0.8.8 ReporteRsjars_0.0.2 [6] pander_0.6.0 formattable_0.2.0.1 magrittr_1.5 tidyr_0.6.1 psych_1.6.12
[11] Hmisc_4.0-2 ggplot2_2.2.1 Formula_1.2-1 survival_2.40-1 lattice_0.20-34
[16] reshape_0.8.6 lazyeval_0.2.0 dplyr_0.5.0 sqldf_0.4-10 RSQLite_1.1-2
[21] gsubfn_0.6-6 proto_1.0.0 rJava_0.9-8

loaded via a namespace (and not attached): [1] Rcpp_0.12.10 png_0.1-7 assertthat_0.1 rprojroot_1.1 digest_0.6.12
[6] mime_0.5 R6_2.2.0 plyr_1.8.4 chron_2.3-49 backports_1.0.4
[11] acepack_1.4.1 evaluate_0.10 gdtools_0.1.4 data.table_1.10.4 R.utils_2.5.0
[16] R.oo_1.21.0 rpart_4.1-10 Matrix_1.2-8 checkmate_1.8.2 rmarkdown_1.3
[21] splines_3.3.3 stringr_1.1.0 foreign_0.8-67 htmlwidgets_0.8 munsell_0.4.3
[26] shiny_1.0.0 httpuv_1.3.3 base64enc_0.1-3 mnormt_1.5-5 rvg_0.1.2
[31] htmltools_0.3.5 nnet_7.3-12 tibble_1.2 gridExtra_2.2.1 htmlTable_1.9
[36] withr_1.0.2 R.methodsS3_1.7.1 grid_3.3.3 xtable_1.8-2 gtable_0.2.0
[41] DBI_0.5-1 scales_0.4.1 stringi_1.1.2 latticeExtra_0.6-28 xml2_1.1.1
[46] lava_1.4.7 RColorBrewer_1.1-2 tools_3.3.3 parallel_3.3.3 colorspace_1.3-2
[51] cluster_2.0.5 memoise_1.0.0 knitr_1.15.1

`

davidgohel commented 7 years ago

Dear anonymous

Thanks a lot for that wonderful minimal example.

.

Despite my previous warning, you keep on opening issues each time you have a question. I am going to ban you from my github account.

David