Learn R Programming

export (version 0.3.0)

table2office: Export statistical output to a table in Microsoft Office / LibreOffice format

Description

Export currently showing R stats object or stats object obj to a Microsoft Office / LibreOffice table

Usage

table2office(
  x = NULL,
  file = "Rtable",
  type = c("PPT", "DOC"),
  append = FALSE,
  digits = 2,
  digitspvals = NULL,
  trim.pval = 1e-16,
  width = NULL,
  height = NULL,
  offx = 1,
  offy = 1,
  font = ifelse(Sys.info()["sysname"] == "Windows", "Arial", "Helvetica")[[1]],
  pointsize = 12,
  add.rownames = FALSE
)

table2ppt(...)

table2doc(...)

Value

flextable object

Arguments

x

given R stats object to export; if set to NULL the output of the previous R command will be exported.

file

name of output file. The .pptx or .docx extension is added automatically.

type

desired output type - "PPT" for PowerPoint and "DOC" for Word.

append

logical value - if TRUE and type="PPT" or "DOC" it will append the table to the given file, where file can also be a given corporate. If append=FALSE any existing file will be overwritten.

digits

number of digits after the comma (for all numeric columns except p-values or degrees of freedom)

digitspvals

number of digits after the comma (for p-values only). The default is equal to digits.

trim.pval

a threshold below which the p-values are trimmed as "< trim.pval".

width

desired width of table in inches. If the given width exceeds the page or slide width, the table width becomes the page/slide width.

height

desired height of table in inches. If the given height exceeds the page or slide height, the table height becomes the page/slide height.

offx

x offset in inches to specify horizontal location of table (only for type=="PPT").

offy

y offset in inches to specify vertical location of table (only for type=="PPT").

font

desired font to use for output table; defaults to "Arial" on Windows systems and to "Helvetica" on other systems.

pointsize

desired font point size.

add.rownames

logical specifying whether or not to add row names.

...

Further arguments to be passed to table2office.

Functions

  • table2ppt(): Export statistical output to a table in a Microsoft Office PowerPoint/ LibreOffice Impress presentation

  • table2doc(): Export statistical output to a table in a Microsoft Office Word/ LibreOffice Writer document

Author

Tom Wenseleers, Christophe Vanderaa

Details

Columns corresponding to degrees of freedom (with header "Df" or "df") are always given as integers. Objects that can be exported with table2office are all those supported by xtable and tidy. The function will first use xtable to format the data. If the data class is not supported by xtable the function will then use tidy. The data classes suported by xtable are:

  • anova

  • aov

  • aovlist

  • data.frame

  • glm

  • gmsar

  • lagImpact

  • lm

  • matrix

  • prcomp

  • sarlm

  • sarlm.pred

  • spautolm

  • sphet

  • splm

  • stsls

  • summary.aov

  • summary.aovlist

  • summary.glm

  • summary.gmsar

  • summary.lm

  • summary.prcomp

  • summary.sarlm

  • summary.spautolm

  • summary.sphet

  • summary.splm

  • summary.stsls

  • table

  • ts

  • zoo

The data classes suported by tidy are:

  • aareg

  • acf

  • Arima

  • betareg

  • biglm

  • binDesign

  • binWidth

  • brmsfit

  • btergm

  • cch

  • character

  • cld

  • coeftest

  • confint.glht

  • cv.glmnet

  • default

  • density

  • dgCMatrix

  • dgTMatrix

  • dist

  • emmGrid

  • ergm

  • felm

  • fitdistr

  • ftable

  • gam

  • Gam

  • gamlss

  • geeglm

  • glht

  • glmnet

  • glmRob

  • gmm

  • htest

  • ivreg

  • kappa

  • kde

  • kmeans

  • Line

  • Lines

  • list

  • lme

  • lmodel2

  • lmRob

  • logical

  • lsmobj

  • manova

  • map

  • Mclust

  • merMod

  • mle2

  • muhaz

  • multinom

  • nlrq

  • nls

  • NULL

  • numeric

  • orcutt

  • pairwise.htest

  • plm

  • poLCA

  • Polygon

  • Polygons

  • power.htest

  • pyears

  • rcorr

  • ref.grid

  • ridgelm

  • rjags

  • roc

  • rowwise_df

  • rq

  • rqs

  • sparseMatrix

  • SpatialLinesDataFrame

  • SpatialPolygons

  • SpatialPolygonsDataFrame

  • spec

  • speedlm

  • stanfit

  • stanreg

  • summary.glht

  • summaryDefault

  • survdiff

  • survexp

  • survfit

  • survreg

  • tbl_df

  • TukeyHSD

See Also

table2tex, table2html, table2spreadsheet

Examples

Run this code
# Create a file name
filen <- tempfile(pattern = "table_aov") # or 
# filen <- paste("YOUR_DIR/table_aov")

# Generate ANOVA output
fit=aov(yield ~ block + N * P + K, data = npk) # 'npk' dataset from base 'datasets'

# Save ANOVA table as a PPT
### Option 1: pass output as object
x=summary(fit)
if (interactive()) 
    table2ppt(x=x,file=filen, digits = 1, digitspvals = 3)
### Option 2: get output from console 
summary(fit)
if (interactive())
    table2ppt(x=x,file=filen, width=5, font="Times New Roman", pointsize=14, 
          digits=4, digitspvals=1, append=TRUE) # append table to previous slide

# Save ANOVA table as a DOC file
if (interactive())
    table2doc(x=x,file=filen, digits = 1, digitspvals = 3)
summary(fit)
if (interactive())
    table2doc(file=filen, width=3.5, font="Times New Roman", pointsize=14, 
          digits=4, digitspvals=1, append=TRUE) # append table at end of document

Run the code above in your browser using DataLab