Package 'eoffice'

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-09-13 03:09:13 UTC
Source: https://github.com/cran/eoffice

Help Index


get the suffix name

Description

get the suffix name

Usage

.getext(x)

Arguments

x

filename


get the prefix name

Description

get the prefix name

Usage

.getfilename(x)

Arguments

x

filename


set first row as column name

Description

set first row as column name

Usage

.setcolnames(file)

Arguments

file

input data frame

Author(s)

Kai Guo


blank theme

Description

blank theme

Usage

.theme_blank()

col2hex gplots

Description

col2hex gplots

Usage

col2hex(cname)

Arguments

cname

color name


convert basic plot to ggplot object

Description

convert basic plot to ggplot object

Usage

convertplot(exp)

Arguments

exp

expression formula of basic plot

Value

ggplot object

Author(s)

Kai Guo

Examples

p <- convertplot(plot(1:10))
class(p)
print(p)

read table from docx

Description

read table from docx

Usage

indocx(filename, header = FALSE)

Arguments

filename

input filename

header

use first row as column name

Author(s)

Kai Guo

Examples

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

Description

import figures and extract the colors used in the figures

Usage

infigure(
  filename,
  format = NULL,
  exclude_col = NULL,
  topn = 10,
  showfig = FALSE,
  showcol = FALSE,
  savegg = FALSE,
  density = 300,
  pages = NULL
)

Arguments

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.

Author(s)

Kai Guo

Examples

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

Description

read tables from ppt and word

Usage

inoffice(filename, format = NULL, header = TRUE)

Arguments

filename

input filename

format

pptx or docx

header

use first row as column name

Author(s)

Kai Guo

Examples

## 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

Description

read table from pptx

Usage

inpptx(filename, header = FALSE)

Arguments

filename

input filename

header

use first row as column name

Author(s)

Kai Guo

Examples

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

Description

export figure to docx

Usage

todocx(
  figure = NULL,
  filename = NULL,
  title = "",
  width = 6,
  height = 6,
  append = FALSE,
  devsize = FALSE,
  units = "in"
)

Arguments

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)

Author(s)

Kai Guo

Examples

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

Description

export graph to MS office

Usage

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"
)

Arguments

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)

Author(s)

Kai Guo

Examples

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

Description

output figures to different formats

Usage

tofigure(figure, format = NULL, filename = "temp.pdf")

Arguments

figure

output figure function, set NULL output the current figure

format

output format (could be ingored)

filename

output filename with different format as suffix

Author(s)

Kai Guo

Examples

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)

Description

export as plotly html (only support ggplot2 object)

Usage

tohtml(figure, filename = "temp.html", save = TRUE)

Arguments

figure

output figure function, set NULL output the current figure

filename

output format (could be ingored)

save

save figure or not (default: TRUE)

Author(s)

Kai Guo

Examples

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

Description

export figure to pptx

Usage

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"
)

Arguments

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)

Author(s)

Kai Guo

Examples

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

Description

write table out to pptx or docx

Usage

totable(data, filename, format = NULL, append = FALSE)

Arguments

data

datasets

filename

output filename

format

pptx or docx

append

append into file

Author(s)

Kai Guo

Examples

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

Description

export figure to pptx

Usage

toxlsx(
  figure = NULL,
  filename = NULL,
  width = 6,
  height = 6,
  devsize = FALSE,
  units = "in"
)

Arguments

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)

Author(s)

Kai Guo

Examples

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"))
}