1. Introduction

eoffice provide wrap functions to export and import graphics and data.frames in R to Microsoft Office (docx, pptx format). And eoffice also provide write out figures with lots of different formats, such as pdf, eps, emf, tiff, svg, wmf, png and jpeg. Since people may work on the platform without GUI support, eoffice also provide function to easily write out figures to all above formats, pptx and docx.

2. Software Usage

2.1 Installation

# library(devtools)
# install_github("guokai8/eoffice")

2.2 Load package

library(eoffice)
library(ggplot2)

2.3 Main Functions

topptx write figures to powerpoint file.

todocx write figures to word file.

totable write data frame or summary results of different model to powerpoint or word files

indocx read tables from word file

inpptx read tables from powerpoint file

tofigure write figures to different output formats.

tohtml write figures to interactive html file

infigure read figures or pdf files into R and extract colors from these files.

 Please install imageMagick to use the _infigure_ function. On Linux you need to install the ImageMagick++ library: on Debian/Ubuntu this is called libmagick++-dev:
sudo apt-get install libmagick++-dev
On Fedora or CentOS/RHEL we need ImageMagick-c++-devel:
sudo yum install ImageMagick-c++-devel

2.4 Quick Tour

plot(mtcars$mpg, mtcars$disp, col = factor(mtcars$cyl), pch = 20)

plot of chunk fig2

topptx(filename = file.path(tempdir(), "mtcars.pptx")) 
##  if you prefer ggplot2 
ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point()

plot of chunk fig2

topptx(filename = file.path(tempdir(), "mtcars.pptx"))
## or todocx(filename = "mtcars.docx")
p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point()
topptx(p, filename = file.path(tempdir(), "mtcars.pptx"), width = 6, height = 4)
## use above method if you want use topptx with ggplot function in a loop
## write out table to office
totable(head(mtcars), filename = file.path(tempdir(), "mtcars.pptx"))
totable(head(mtcars), filename = file.path(tempdir(), "mtcars.pptx"))
## append was supported if you want add figures or tables.
## Now support direct output of common objects produced by R statistical functions
tt <- t.test(wt ~ am, mtcars)
totable(tt, filename = file.path(tempdir(), "mtcars.pptx"))
totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.pptx"))
## inpptx and indocx provide function read the tables in pptx or docx
tabs <- inpptx(filename = file.path(tempdir(), "mtcars.pptx"), header = TRUE)
## Warning: `filter_()` is deprecated as of dplyr 0.7.0.
## Please use `filter()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: `select_()` is deprecated as of dplyr 0.7.0.
## Please use `select()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## output different figure formats
p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point()
tofigure(p, filename = file.path(tempdir(), "mtcars.pdf"))
## [1] "../../../../../../../../../../var/folders/p_/0q7dys0x1g53nw6wypk8_qgm0000gn/T/RtmpkIGutW/mtcars.pdf"
tofigure(ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point(), filename = file.path(tempdir(), "mtcars.eps"))
## [1] "../../../../../../../../../../var/folders/p_/0q7dys0x1g53nw6wypk8_qgm0000gn/T/RtmpkIGutW/mtcars.eps"
## Not support emf and eps formats 
# infigure(file.path(tempdir(), "mtcars.pdf"),exclude_col = c("white","black")) 
## if you use basic plot function or other plot function you need first use convertplot to convert 
## it to ggplot object when you are working on the platform without GUI
## p <- convertplot(plot(1:10))
## tofigure(p, filename = file.path(tempdir(), "mtcars.pdf"))
## topptx(p, filename = file.path(tempdir(), "mtcars.pptx"))
## if you use ggplot like function you don't need to transform the format

Note

eoffice mainly depends on officer and rvg package which include lots of fantastic functions. Here, eoffice provides simplified functions which could be save some time to learn the complete functions from above packages. And there are some packages provide these functions. Comparing with these packages, eoffice include own features which I think really helpful to me. Besides, eoffice also provide functions to read tables from pptx and docx. Read graphics functions will be available soon.

Contact information

For any questions please contact guokai8@gmail.com