Title: | Export or Graph and Tables to 'Microsoft' Office and Import Figures and Tables |
---|---|
Description: | Provides wrap functions to export and import graphics and data frames in R to 'microsoft' office. And This package also provide write out figures with lots of different formats. Since people may work on the platform without GUI support, the package also provide function to easily write out figures to lots of different type of formats. Now this package provide function to extract colors from all types of figures and pdf files. |
Authors: | Kai Guo [aut, cre] |
Maintainer: | Kai Guo <[email protected]> |
License: | GPL-2 |
Version: | 0.2.2 |
Built: | 2024-11-12 03:10:43 UTC |
Source: | https://github.com/cran/eoffice |
get the suffix name
.getext(x)
.getext(x)
x |
filename |
get the prefix name
.getfilename(x)
.getfilename(x)
x |
filename |
set first row as column name
.setcolnames(file)
.setcolnames(file)
file |
input data frame |
Kai Guo
col2hex gplots
col2hex(cname)
col2hex(cname)
cname |
color name |
convert basic plot to ggplot object
convertplot(exp)
convertplot(exp)
exp |
expression formula of basic plot |
ggplot object
Kai Guo
p <- convertplot(plot(1:10)) class(p) print(p)
p <- convertplot(plot(1:10)) class(p) print(p)
read table from docx
indocx(filename, header = FALSE)
indocx(filename, header = FALSE)
filename |
input filename |
header |
use first row as column name |
Kai Guo
totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.docx")) tabs <- indocx(filename = file.path(tempdir(), "mtcars.docx"), header = TRUE) tabs
totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.docx")) tabs <- indocx(filename = file.path(tempdir(), "mtcars.docx"), header = TRUE) tabs
import figures and extract the colors used in the figures
infigure( filename, format = NULL, exclude_col = NULL, topn = 10, showfig = FALSE, showcol = FALSE, savegg = FALSE, density = 300, pages = NULL )
infigure( filename, format = NULL, exclude_col = NULL, topn = 10, showfig = FALSE, showcol = FALSE, savegg = FALSE, density = 300, pages = NULL )
filename |
input filename |
format |
format of input file |
exclude_col |
vector of colors to be excluded from the analysis |
topn |
display the most frequent colors |
showfig |
display the figure or not (default: FALSE) |
showcol |
display extracted colors or not (default: FALSE) |
savegg |
save the figure as ggplot2 object or not (default: FALSE) |
density |
resolution to render pdf |
pages |
integer vector with page numbers (pdf file). Defaults to all pages. |
Kai Guo
if(interactive()){ require(ggplot2) p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tofigure(p,filename = file.path(tempdir(), "mtcars.pdf")) pp <- infigure(filename = file.path(tempdir(), "mtcars.pdf"), exclude_col="white") pp }
if(interactive()){ require(ggplot2) p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tofigure(p,filename = file.path(tempdir(), "mtcars.pdf")) pp <- infigure(filename = file.path(tempdir(), "mtcars.pdf"), exclude_col="white") pp }
read tables from ppt and word
inoffice(filename, format = NULL, header = TRUE)
inoffice(filename, format = NULL, header = TRUE)
filename |
input filename |
format |
pptx or docx |
header |
use first row as column name |
Kai Guo
## use tempdir for the example totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.docx")) tabs <- inoffice(filename = file.path(tempdir(), "mtcars.docx"), header = TRUE) tabs
## use tempdir for the example totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.docx")) tabs <- inoffice(filename = file.path(tempdir(), "mtcars.docx"), header = TRUE) tabs
read table from pptx
inpptx(filename, header = FALSE)
inpptx(filename, header = FALSE)
filename |
input filename |
header |
use first row as column name |
Kai Guo
totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.pptx")) tabs <- inpptx(filename = file.path(tempdir(), "mtcars.pptx"), header = TRUE) tabs
totable(t.test(wt ~ am, mtcars), filename = file.path(tempdir(), "mtcars.pptx")) tabs <- inpptx(filename = file.path(tempdir(), "mtcars.pptx"), header = TRUE) tabs
export figure to docx
todocx( figure = NULL, filename = NULL, title = "", width = 6, height = 6, append = FALSE, devsize = FALSE, units = "in" )
todocx( figure = NULL, filename = NULL, title = "", width = 6, height = 6, append = FALSE, devsize = FALSE, units = "in" )
figure |
plot figure function |
filename |
output filename |
title |
title for the figure |
width |
width of the output figure |
height |
height of the output figure |
append |
append or not |
devsize |
Boolean value show use device size or not (default = FALSE) |
units |
the units in which to return the value – inches, cm, or pixels (device units) |
Kai Guo
if(interactive()){ plot(mtcars$mpg, mtcars$disp) todocx(filename = file.path(tempdir(), "mtcars.docx")) ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() todocx(filename = file.path(tempdir(), "mtcars.docx"), height = 6, width = 4) }
if(interactive()){ plot(mtcars$mpg, mtcars$disp) todocx(filename = file.path(tempdir(), "mtcars.docx")) ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() todocx(filename = file.path(tempdir(), "mtcars.docx"), height = 6, width = 4) }
export graph to MS office
toffice( figure = NULL, format = "pptx", filename = "temp.pptx", nr = 1, nc = 1, irow = 1, icol = 1, onsame = FALSE, title = "", left = 0.15, top = 0.15, append = FALSE, width = 4, height = 4, devsize = FALSE, units = "in" )
toffice( figure = NULL, format = "pptx", filename = "temp.pptx", nr = 1, nc = 1, irow = 1, icol = 1, onsame = FALSE, title = "", left = 0.15, top = 0.15, append = FALSE, width = 4, height = 4, devsize = FALSE, units = "in" )
figure |
plot figure function |
format |
file format |
filename |
output filename |
nr , nc
|
two numbers to indicate the figures will be drawn in an nr-by-nc array on the device by columns or rows, respectively. |
irow , icol
|
two number to indicate which row or column for the figure to be drawn |
onsame |
Boolean value show to draw on same slide or not |
title |
title for the figure |
left , top
|
two numbers which gives the number of lines of margin to be specified on the left and right sides of the plot |
append |
append or not |
width |
width of the output figure |
height |
height of the output figure |
devsize |
Boolean value show use device size or not (default = FALSE) |
units |
the units in which to return the value – inches, cm, or pixels (device units) |
Kai Guo
if(interactive()){ plot(mtcars$mpg, mtcars$disp) toffice(filename = file.path(tempdir(), "mtcars.pptx"), format = "pptx") ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() toffice(filename = file.path(tempdir(), "mtcars.pptx"),format = "pptx") }
if(interactive()){ plot(mtcars$mpg, mtcars$disp) toffice(filename = file.path(tempdir(), "mtcars.pptx"), format = "pptx") ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() toffice(filename = file.path(tempdir(), "mtcars.pptx"),format = "pptx") }
output figures to different formats
tofigure(figure, format = NULL, filename = "temp.pdf")
tofigure(figure, format = NULL, filename = "temp.pdf")
figure |
output figure function, set NULL output the current figure |
format |
output format (could be ingored) |
filename |
output filename with different format as suffix |
Kai Guo
require(ggplot2) p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tofigure(p,filename = file.path(tempdir(), "mtcars.pdf")) ## or use ggplot directly tofigure(ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point(), filename = file.path(tempdir(), "mtcars.eps")) ## 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"))
require(ggplot2) p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tofigure(p,filename = file.path(tempdir(), "mtcars.pdf")) ## or use ggplot directly tofigure(ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point(), filename = file.path(tempdir(), "mtcars.eps")) ## 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"))
export as plotly html (only support ggplot2 object)
tohtml(figure, filename = "temp.html", save = TRUE)
tohtml(figure, filename = "temp.html", save = TRUE)
figure |
output figure function, set NULL output the current figure |
filename |
output format (could be ingored) |
save |
save figure or not (default: TRUE) |
Kai Guo
if(interactive()){ require(ggplot2) p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tohtml(p,filename = file.path(tempdir(), "mtcars.html")) ## or use ggplot directly ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tohtml(save = FALSE) }
if(interactive()){ require(ggplot2) p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tohtml(p,filename = file.path(tempdir(), "mtcars.html")) ## or use ggplot directly ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() tohtml(save = FALSE) }
export figure to pptx
topptx( figure = NULL, filename = NULL, nr = 1, nc = 1, irow = 1, icol = 1, onsame = FALSE, title = "", left = 0.15, top = 0.15, width = 6, height = 6, append = FALSE, devsize = FALSE, units = "in" )
topptx( figure = NULL, filename = NULL, nr = 1, nc = 1, irow = 1, icol = 1, onsame = FALSE, title = "", left = 0.15, top = 0.15, width = 6, height = 6, append = FALSE, devsize = FALSE, units = "in" )
figure |
plot figure function |
filename |
output filename |
nr , nc
|
two numbers to indicate the figures will be drawn in an nr-by-nc array on the device by columns or rows, respectively. |
irow , icol
|
the number to indicate which row or column for the figure to be drawn |
onsame |
Boolean value show to draw on same slide or not |
title |
title for the figure |
left , top
|
two numbers which gives the number of lines of margin to be specified on the left and right sides of the plot |
width |
width of the output figure |
height |
height of the output figure |
append |
append or not |
devsize |
Boolean value show use device size or not (default = FALSE) |
units |
the units in which to return the value – inches, cm, or pixels (device units) |
Kai Guo
if(interactive()){ plot(mtcars$mpg, mtcars$disp) topptx(filename = file.path(tempdir(), "mtcars.pptx")) ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() topptx(filename = file.path(tempdir(), "mtcars.pptx")) }
if(interactive()){ plot(mtcars$mpg, mtcars$disp) topptx(filename = file.path(tempdir(), "mtcars.pptx")) ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() topptx(filename = file.path(tempdir(), "mtcars.pptx")) }
write table out to pptx or docx
totable(data, filename, format = NULL, append = FALSE)
totable(data, filename, format = NULL, append = FALSE)
data |
datasets |
filename |
output filename |
format |
pptx or docx |
append |
append into file |
Kai Guo
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")) totable(head(mtcars), filename = file.path(tempdir(), "mtcars.docx"))
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")) totable(head(mtcars), filename = file.path(tempdir(), "mtcars.docx"))
export figure to pptx
toxlsx( figure = NULL, filename = NULL, width = 6, height = 6, devsize = FALSE, units = "in" )
toxlsx( figure = NULL, filename = NULL, width = 6, height = 6, devsize = FALSE, units = "in" )
figure |
plot figure function |
filename |
output filename |
width |
width of the output figure |
height |
height of the output figure |
devsize |
Boolean value show use device size or not (default = FALSE) |
units |
the units in which to return the value – inches, cm, or pixels (device units) |
Kai Guo
if(interactive()){ plot(mtcars$mpg, mtcars$disp) toxlsx(filename = file.path(tempdir(), "mtcars.xlsx")) ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() toxlsx(filename = file.path(tempdir(), "mtcars.xlsx")) }
if(interactive()){ plot(mtcars$mpg, mtcars$disp) toxlsx(filename = file.path(tempdir(), "mtcars.xlsx")) ## use ggplot2 ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point() toxlsx(filename = file.path(tempdir(), "mtcars.xlsx")) }