report.doc This function enables to export the table created with report.quali report.quanti or report.lsmeans to a Microsoft Word or a R markdown document.

It's also possible to use report.doc to have a preview of the table in HTML format if the doc argument is NULL.

For more examples see the website: ClinReport website

report.doc(table, ...)

# S3 method for desc
report.doc(table, title = NULL, colspan.value = NULL,
  doc = NULL, init.numbering = F, numbering = T,
  font.name = "Times", page.break = T, font.size = 10, valign = F,
  ...)

# S3 method for anova
report.doc(table, title = "Anova table",
  type.anova = 3, doc = NULL, numbering = T, init.numbering = F,
  font.name = "Times", font.size = 10, page.break = T,
  pretty.label = FALSE, ...)

Arguments

table

A desc object that report statistics (the results of report.quanti or report.quali)

...

Other arguments

title

Character. The title of the table

colspan.value

Character. Add the label of the x1 variable levels (typically "Treatment Groups")

doc

NULL or a rdocx object

init.numbering

Logical. If TRUE Start numbering of the output at 1, otherwise it increase the output numbering of 1 unit

numbering

Logical. If TRUE Output numbers are added before the title.

font.name

Character. Passed to font function. Set the font of the output in Word

page.break

Logical. If TRUE it adds a page break after the output. Default to TRUE

font.size

Numeric. Passed to fontsize function. Set the font size of the output in Word

valign

Logical. If TRUE it aligns vertically the levels of the merged cells in the first column

type.anova

Passed to Anova function from car package (see its documentation).

pretty.label

Logical. Default to FALSE. If TRUE, use the function make.label with default option on the rownames of the anova table

anova

Logical. Used to specify if the table is an anova table. By default it's not

Value

A flextable object (if doc=NULL) or a rdocx object (if doc= an rdocx object).

Details

This function creates a flextable object from a desc object.

For Microsoft Word documents:

The argument doc should be used so the flextable is added to a rdocx object.

Like:

doc=read_docx()

tab=report.quanti(data=data,y="y_numeric",x1="GROUP")

doc=report.doc(tab,doc=doc)

For R markdown documents:

Just don't use the doc argument. Something like:

```{r, include=TRUE}
tab=report.quanti(data=data,y="y_numeric",x1="GROUP")
doc=report.doc(tab)
doc
```

See also

Examples

##################### # Import libraries ##################### library(officer) library(flextable) library(reshape2) library(emmeans) library(lme4) library(nlme) library(ggplot2) library(car)
#> Le chargement a nécessité le package : carData
#> Registered S3 methods overwritten by 'car': #> method from #> influence.merMod lme4 #> cooks.distance.influence.merMod lme4 #> dfbeta.influence.merMod lme4 #> dfbetas.influence.merMod lme4
library(xtable)
#> #> Attachement du package : 'xtable'
#> The following objects are masked from 'package:flextable': #> #> align, display
##################### # Load data ##################### data(datafake) head(datafake)
#> y_numeric y_logistic y_poisson baseline VAR GROUP TIMEPOINT SUBJID #> 1 -0.4203490 1 5 -0.4203490 Cat 1 A D0 Subj 1 #> 2 -0.1570941 1 5 -0.1570941 Cat 2 A D0 Subj 1 #> 3 NA 0 3 -2.0853720 Cat 2 A D0 Subj 1 #> 4 -0.4728527 0 5 -0.4728527 Cat 1 A D0 Subj 1 #> 5 -0.8651713 1 4 -0.8651713 Cat 1 A D0 Subj 1 #> 6 -1.5476907 1 3 -1.5476907 Cat 1 A D0 Subj 1
# Removing baseline data for the model data.mod=droplevels(datafake[datafake$TIMEPOINT!="D0",]) ##################### # Create your stats tables and graphics ##################### # Quatitative stats (2 explicative variables) ################################## # since it's a big enough table, we don't want it to overlap 2 pasges # so we split it in two with split.desc function tab1=report.quanti(data=datafake,y="y_numeric", x1="GROUP",x2="TIMEPOINT",at.row="TIMEPOINT",subjid="SUBJID") s=split(tab1,variable="TIMEPOINT",at=3) tab1.1=s$x1 tab1.2=s$x2 gg=plot(tab1,title="Mean response evolution as a function of time by treatment group", legend.label="Treatment groups",ylab="Y mean") # Qualitative stats (2 explicative variables) ################################## tab2=report.quali(data=datafake,y="y_logistic", x1="GROUP",x2="TIMEPOINT",at.row="TIMEPOINT",total=TRUE,subjid="SUBJID") gg2=plot(tab2,title="Response distribution (%) by day and treatment group", legend.label="Y levels") # Qualitative stats (no explicative variable) ################################### tab3=report.quali(data=datafake,y="VAR",y.label="Whatever") # Qualitative stats (no explicative variables ; add number of subjects in header)# tab4=report.quali(data=datafake,y="VAR",y.label="Whatever", subjid="SUBJID") # Qualitative stats (1 explicative variable)####################################### tab5=report.quali(data=datafake,y="VAR",y.label="Whatever",x1="GROUP", subjid="SUBJID") # Quantitative stats (1 explicative variable)####################################### tab6=report.quanti(data=datafake,y="y_numeric",y.label="Whatever 2",x1="GROUP", subjid="SUBJID") # Quali-Quanti table tab5.6=regroup(tab5,tab6) # Linear model (order 2 interaction): Anova and LS-Means reporting ################ mod1=lm(y_numeric~baseline+GROUP+TIMEPOINT+GROUP*TIMEPOINT,data=data.mod) test1=emmeans(mod1,~GROUP|TIMEPOINT) anov1=Anova(mod1) tab.mod1=report.lsmeans(lsm=test1) gg.mod1=plot(tab.mod1,title="LS-Means response evolution as a function of time\n by treatment group (95% CI)", legend.label="Treatment groups",ylab="Y mean",add.ci=TRUE) # Linear model (1 group only): Anova and LS-Means and graph reporting ################ mod2=lm(y_numeric~baseline+GROUP,data=data.mod) anov2=Anova(mod2,type=3) test2=emmeans(mod2,~GROUP) tab.mod2=report.lsmeans(lsm=test2) gg.mod2=plot(tab.mod2,title="LS-Means response\nby treatment group (95% CI)", legend.label="Treatment groups",ylab="Y mean",add.ci=TRUE) # Linear mixed model (order 2 interaction): # Anova and LS-Means and graph reporting ################# mod3=lme(y_numeric~baseline+GROUP+TIMEPOINT+GROUP*TIMEPOINT, random=~1|SUBJID,data=data.mod,na.action=na.omit) anov3=Anova(mod3,3) test3=emmeans(mod3,~GROUP|TIMEPOINT) tab.mod3=report.lsmeans(lsm=test3) gg.mod3=plot(tab.mod3,title="LS-Means response evolution as a function of time\n by treatment group (95% CI Mixed model)", legend.label="Treatment groups",ylab="Y mean",add.ci=TRUE) # Contrast example contr=contrast(test3, "trt.vs.ctrl", ref = "A") tab.mod3.contr=report.lsmeans(lsm=contr) gg.mod3.contr=plot(tab.mod3.contr,title="LS-Means contrast versus reference A\n (95% CI Mixed model)", legend.label="Treatment groups",ylab="Y mean",add.ci=TRUE,add.line=FALSE) ############################################################ # Generalized Logistic Linear model (order 2 interaction): ############################################################ # Anova LS-Means and graph reporting ########## mod4=glm(y_logistic~baseline+GROUP+TIMEPOINT+GROUP*TIMEPOINT, family=binomial,data=data.mod,na.action=na.omit) anov4=Anova(mod4,3) test4=emmeans(mod4,~GROUP|TIMEPOINT) tab.mod4=report.lsmeans(lsm=test4,at.row="TIMEPOINT") gg.mod4=plot(tab.mod4,title="LS-Means response evolution as a function of time\n by treatment group (95% CI Logistic model)", legend.label="Treatment groups",ylab="Y mean",add.ci=TRUE) # Generalized Poisson Linear model (order 2 interaction): # Anova LS-Means and graph reporting #' mod5=glm(y_poisson~baseline+GROUP+TIMEPOINT+GROUP*TIMEPOINT, family=poisson,data=data.mod,na.action=na.omit) anov5=Anova(mod5,3) test5=emmeans(mod5,~GROUP|TIMEPOINT) tab.mod5=report.lsmeans(lsm=test5,at.row="TIMEPOINT") gg.mod5=plot(tab.mod5,title="LS-Means response evolution as a function of time\n by treatment group (95% CI Poisson model)", legend.label="Treatment groups",ylab="Y mean",add.ci=TRUE) ##################### # Create your report ##################### doc=read_docx() doc=body_add_toc(doc) doc=body_add_par(doc,"A beautiful reporting using ClinReport", style = "heading 1") doc=body_add_par(doc,"Descriptive statistics", style = "heading 2") doc=report.doc(tab1.1,title="Quantitative statistics (2 explicative variables) (Table 1/2)", colspan.value="Treatment group",doc=doc,init.numbering=TRUE, page.break=FALSE) doc=report.doc(tab1.2,title="Quantitative statistics (2 explicative variables) (Table 2/2)", colspan.value="Treatment group",doc=doc) doc=body_add_par(doc,"Corresponding graphic of outputs 1 & 2", style ="Normal") doc=body_add_gg(doc, value = gg, style = "centered" ) doc=body_add_break(doc) doc=report.doc(tab2,title="Qualitative statistics (2 explicative variables)", colspan.value="Treatment group",doc=doc) doc=report.doc(tab2,title="The same with smaller font size", colspan.value="Treatment group",doc=doc,font.size=8) doc=body_add_par(doc,"Corresponding graphic of output 3", style ="Normal") doc=body_add_gg(doc, value = gg2, style = "centered" ) doc=body_add_break(doc) doc=body_add_par(doc,"Example of mixing qualitative and quantitative statistics with the function regroup", style ="Normal") doc=report.doc(tab5.6,title="Quali-Qanti statistics (1 variable only)",doc=doc) doc=body_add_par(doc,"Statistical model results", style = "heading 2") doc=body_add_par(doc,"Model 1", style = "heading 3") doc=body_add_par(doc,"Anova table example", style = "Normal") doc=report.doc(anov1,doc=doc) doc=body_add_par(doc,"LS-Means example", style = "Normal") doc=report.doc(tab.mod1,title="Linear Model LS-Means results using lm with interactions", colspan.value="Treatment group",doc=doc) doc=body_add_gg(doc, value = gg.mod1, style = "centered" ) doc=body_add_break(doc) doc=body_add_par(doc,"Model 2", style = "heading 3") doc=report.doc(anov2,doc=doc) doc=report.doc(tab.mod2,title="Linear Model LS-Means results using lm without interaction", colspan.value="Treatment group",doc=doc) doc=body_add_gg(doc, value = gg.mod2, style = "centered" ) doc=body_add_break(doc) doc=body_add_par(doc,"Model 3", style = "heading 3") doc=report.doc(anov3,doc=doc) doc=report.doc(tab.mod3,title="Linear Mixed Model LS-Means results using lme", colspan.value="Treatment group",doc=doc) doc=body_add_gg(doc, value = gg.mod3, style = "centered" ) doc=body_add_break(doc) doc=report.doc(tab.mod3.contr,title="LS-Means Contrast example", colspan.value="Timepoints",doc=doc) doc=body_add_gg(doc, value = gg.mod3.contr, style = "centered" ) doc=body_add_break(doc) doc=body_add_par(doc,"Model 4", style = "heading 3") doc=report.doc(anov4,doc=doc) doc=report.doc(tab.mod4,title="Generalized Linear Mixed Model LS-Means results using glm", colspan.value="Treatment group",doc=doc) doc=body_add_gg(doc, value = gg.mod4, style = "centered" ) doc=body_add_break(doc) doc=body_add_par(doc,"Model 5", style = "heading 3") doc=report.doc(anov5,doc=doc) doc=report.doc(tab.mod5,title="Poisson Model LS-Means results", colspan.value="Treatment group",doc=doc) doc=body_add_gg(doc, value = gg.mod5, style = "centered" ) file=paste(tempfile(),".docx",sep="") <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD print(doc, target =file)
#> Note: zip::zip() is deprecated, please use zip::zipr() instead
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpWari3b/file2ac4402d5404.docx"
======= print(doc, target =file)
#> Note: zip::zip() is deprecated, please use zip::zipr() instead
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpGUh2VY/file2f20196f354c.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/Rtmp8oexhK/file30687edd322d.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpwvypGw/filec5422d43528.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpW2PZ3r/filee201ca0168f.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpWw7By6/file405874df1694.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpWwJ4u7/file35f074e555a.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/Rtmpi29jZo/file4b382ae9b76.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/RtmpeqkaF4/file2b7c56114c25.docx"
>>>>>>> refs/heads/Dev ======= print(doc, target =file)
#> [1] "C:/Users/jfcollin/AppData/Local/Temp/Rtmpa6BHIT/file25b0639c13e3.docx"
>>>>>>> refs/heads/Dev