Repository: tomwenseleers/export
Branch: master
Commit: 44d9f715e643
Files: 49
Total size: 112.5 KB
Directory structure:
gitextract__yr00ue_/
├── .Rbuildignore
├── .github/
│ ├── .gitignore
│ └── workflows/
│ └── check-standard.yaml
├── .gitignore
├── DESCRIPTION
├── NAMESPACE
├── NEWS.md
├── R/
│ ├── export
│ ├── export.rdb
│ ├── export.rdx
│ ├── graph2bitmap.R
│ ├── graph2office.R
│ ├── graph2vector.R
│ ├── rgl2bitmap.R
│ ├── table2office.R
│ ├── table2spreadsheet.R
│ ├── table2tex.R
│ └── utils.R
├── README.md
├── examples/
│ ├── graph2bitmap.R
│ ├── graph2office.R
│ ├── graph2vector.R
│ ├── rgl2bitmap.R
│ ├── table2office.R
│ ├── table2spreadsheet.R
│ └── table2tex.R
├── inst/
│ └── templates/
│ ├── A1_landscape.pptx
│ ├── A1_portrait.pptx
│ ├── A2_landscape.pptx
│ ├── A2_portrait.pptx
│ ├── A3_landscape.docx
│ ├── A3_landscape.pptx
│ ├── A3_portrait.docx
│ ├── A3_portrait.pptx
│ ├── A4_landscape.docx
│ ├── A4_landscape.pptx
│ ├── A4_portrait.docx
│ ├── A4_portrait.pptx
│ ├── A5_landscape.docx
│ ├── A5_landscape.pptx
│ ├── A5_portrait.docx
│ └── A5_portrait.pptx
└── man/
├── graph2bitmap.Rd
├── graph2office.Rd
├── graph2vector.Rd
├── rgl2bitmap.Rd
├── table2office.Rd
├── table2spreadsheet.Rd
└── table2tex.Rd
================================================
FILE CONTENTS
================================================
================================================
FILE: .Rbuildignore
================================================
examples
^\.Rproj\.user$
cran-comments.md
^revdep$
^.git$
^export.Rproj$
^.*\.Rproj$
.Rhistory
.RData
^\.github$
================================================
FILE: .github/.gitignore
================================================
*.html
================================================
FILE: .github/workflows/check-standard.yaml
================================================
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
schedule:
# Run every 1st of the month at 9:00 UTC
- cron: '00 9 1 * *'
name: R-CMD-check
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
# Install X11 dependencies on macOS, otherwise an error is thrown:
# Warning: Loading rgl's DLL failed.
# This build of rgl depends on XQuartz, which failed to load.
# See the discussion in https://stackoverflow.com/a/66127391/2554330
- name: Install X11 dependencies on MacOS
if: runner.os == 'macOS'
run: |
brew install --cask xquartz
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/check-r-package@v2
env:
RGL_USE_NULL: TRUE
DISPLAY: ":99"
with:
upload-snapshots: true
================================================
FILE: .gitignore
================================================
.Rproj.user
.Rhistory
export.Rproj
================================================
FILE: DESCRIPTION
================================================
Package: export
Type: Package
Title: Streamlined Export of Graphs and Data Tables
Version: 0.3.1
Authors@R: c(person("Tom", "Wenseleers", role = c("aut", "cre"),
email = "tom.wenseleers@kuleuven.be"),
person("Christophe", "Vanderaa", role = c("aut"),
email = "christophe.vanderaa@kuleuven.be"))
Maintainer: Tom Wenseleers <tom.wenseleers@kuleuven.be>
Depends: R (>= 3.0)
Imports: stats,
utils,
datasets,
grDevices,
officer (>= 0.2.2),
rvg (>= 0.1.8),
xtable (>= 1.8-2),
flextable (>= 0.4.3),
xml2 (>= 1.2.0),
stargazer (>= 5.2.1),
openxlsx (>= 4.0.17),
broom (>= 0.4.4),
devEMF (>= 3.8)
Suggests: rgl (>= 0.99.16),
ggplot2 (>= 1.0)
Description: Easily export 'R' graphs and statistical output to 'Microsoft
Office' / 'LibreOffice', 'Latex' and 'HTML' Documents, using sensible defaults
that result in publication-quality output with simple, straightforward commands.
Output to 'Microsoft Office' is in editable 'DrawingML' vector format for
graphs, and can use corporate template documents for styling. This enables
the production of standardized reports and also allows for manual tidy-up
of the layout of 'R' graphs in 'Powerpoint' before final publication. Export
of graphs is flexible, and functions enable the currently showing R graph
or the currently showing 'R' stats object to be exported, but also allow the
graphical or tabular output to be passed as objects. The package relies on package
'officer' for export to 'Office' documents,and output files are also fully compatible
with 'LibreOffice'. Base 'R', 'ggplot2' and 'lattice' plots are supported, as
well as a wide variety of 'R' stats objects, via wrappers to xtable(), broom::tidy()
and stargazer(), including aov(), lm(), glm(), lme(), glmnet() and coxph() as
well as matrices and data frames and many more...
License: GPL-2
BugReports: https://github.com/tomwenseleers/export/issues
RoxygenNote: 7.2.2
Encoding: UTF-8
NeedsCompilation: no
Packaged: 2018-09-17 15:51:05 UTC; Ento
================================================
FILE: NAMESPACE
================================================
# Generated by roxygen2: do not edit by hand
export(graph2bitmap)
export(graph2doc)
export(graph2eps)
export(graph2jpg)
export(graph2office)
export(graph2pdf)
export(graph2png)
export(graph2ppt)
export(graph2svg)
export(graph2tif)
export(graph2vector)
export(rgl2bitmap)
export(rgl2png)
export(table2csv)
export(table2csv2)
export(table2doc)
export(table2excel)
export(table2html)
export(table2office)
export(table2ppt)
export(table2spreadsheet)
export(table2tex)
import(datasets)
import(flextable)
import(officer)
import(openxlsx)
import(rvg)
import(stargazer)
import(stats)
import(xml2)
importFrom(broom,tidy)
importFrom(devEMF,emf)
importFrom(grDevices,cairo_pdf)
importFrom(grDevices,cairo_ps)
importFrom(grDevices,dev.cur)
importFrom(grDevices,dev.list)
importFrom(grDevices,dev.off)
importFrom(grDevices,dev.size)
importFrom(grDevices,hcl)
importFrom(grDevices,jpeg)
importFrom(grDevices,pdf)
importFrom(grDevices,png)
importFrom(grDevices,postscript)
importFrom(grDevices,recordPlot)
importFrom(grDevices,svg)
importFrom(grDevices,tiff)
importFrom(utils,browseURL)
importFrom(utils,capture.output)
importFrom(utils,head)
importFrom(utils,methods)
importFrom(utils,tail)
importFrom(utils,write.csv)
importFrom(utils,write.csv2)
importFrom(xtable,xtable)
================================================
FILE: NEWS.md
================================================
# export 0.3
### New features
* Fixed NOTE that resulted in some temporary files being left on non-interactive
Debian systems.
# export 0.2.2.9000
### New features
* Fixed bug when no graphical devices are available fro exporting graphs (as pointed out by guokai8 on GitHub)
# export 0.2.2 Beta
### New features
* Made export use officer and flextable rather than ReporteRs and rtable, as the latter wtwo ere removed from CRAN.
* Created table2spreadsheet() to generate table in a Microsoft Excel / LibreOffice Calc file or in a CSV (using either comma or semicolon as separation)
* table2spreadsheet() and table2office() use the "broom" package additionaly to the "xtable" package which allows for more data classes to be exported as tables
### Removed features
* Removed graph2tex() as it is better to use graph2bitmap or graph2pdf and to manually insert these in the LaTex document
# export 0.2.1 Beta
### New features
* Created table2office() to generate tables in a presentation (Microsoft PowerPoint or LibreOffice) or in a document (Microsoft Word or LibreOffice) with similar behavior as graph2office().
# export 0.2.0 Beta
### New features
* Automatic selection of paper size based on graph size in MS Office export
* Added Latex export of graphs & tables
================================================
FILE: R/export
================================================
# File share/R/nspackloader.R
# Part of the R package, http://www.R-project.org
#
# Copyright (C) 1995-2012 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License is available at
# http://www.r-project.org/Licenses/
local({
info <- loadingNamespaceInfo()
pkg <- info$pkgname
ns <- .getNamespace(as.name(pkg))
if (is.null(ns))
stop("cannot find namespace environment for ", pkg, domain = NA);
dbbase <- file.path(info$libname, pkg, "R", pkg)
lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.")
})
================================================
FILE: R/graph2bitmap.R
================================================
#' Save currently active R graph to bitmap format
#'
#' Save the currently active R graph or a graph passed as an object or function
#' to bitmap format with sensible defaults
#'
#'
#' @importFrom grDevices dev.size
#' @importFrom grDevices png
#' @importFrom grDevices tiff
#' @importFrom grDevices jpeg
#' @aliases graph2bitmap graph2png graph2tif graph2jpg
#' @param x given \code{ggplot2} plot or \code{lattice} plot object to export; if
#' set to \code{NULL} the currently active R graph will be exported; not
#' supported for base R plots.
#' @param file name of output file. Any extension is ignored and added
#' according to the requested output type. If file already exists it is overwritten.
#' @param fun plot passed on as a function used to create it; useful especially
#' for base R plots.
#' @param type desired output type - \code{PNG}, \code{TIF} or \code{JPG} are currently supported.
#' \code{PNG} is the preferred format, as it is a lossless format, and compresses better
#' than \code{TIF}.
#' @param aspectr desired width to height aspect ratio. If set to \code{NULL}, the
#' aspect ratio of the graphics device is used. Can also be combined with one
#' value for either the desired width or height of the graph.
#' @param width desired width in inches; can be combined with a desired
#' aspect ratio aspectr.
#' @param height desired height in inches; can be combined with a desired
#' aspect ratio aspectr.
#' @param dpi desired output in dpi; defaults to 600 dpi.
#' @param scaling scale width & height by a certain percentage.
#' @param font desired font to use for labels in PNG and TIFF output; defaults to
#' \code{"Arial"} on Windows systems and to \code{"Helvetica"} on other systems.
#' @param bg desired background colour, e.g. \code{"white"} or \code{"transparent"}.
#' @param cairo logical, specifying whether or not to use \code{Cairographics} for export.
#' @param tiffcompression compression to use for \code{TIF} files.
#' @param jpegquality quality of \code{JPEG} compression.
#' @param \dots any other options are passed on to \code{grDevices}' \code{\link{png}},
#' \code{\link{tiff}}, or \code{\link{jpeg}} function (according to the supplied \code{type}).
#' @return No return value
#' @author Tom Wenseleers
#' @example examples/graph2bitmap.R
#' @seealso \code{\link{graph2office}}, \code{\link{graph2vector}}, \code{\link{graph2svg}}, \code{\link{graph2pdf}},
#' \code{\link{graph2eps}}
#' @export
#'
graph2bitmap = function(x = NULL, file = "Rplot", fun = NULL,
type = c("PNG","JPG","TIF"), aspectr = NULL,
width = NULL, height = NULL, dpi = 300, scaling = 100,
font = ifelse(Sys.info()["sysname"] == "Windows", "Arial","Helvetica")[[1]],
bg = "white", cairo = TRUE,
tiffcompression = c("lzw","rle","jpeg","zip","lzw+p","zip+p"),
jpegquality = 99, ...) {
# Get initial graphical state
dev.init <- dev.list()
# Format arguments
type <- toupper(type)
type <- match.arg(type, c("PNG", "JPG", "TIF"))
if (type == "JPG") type <- "JPEG"
if (type == "TIFF") type <- "TIF"
tiffcompression <- match.arg(tiffcompression)
ext <- paste0(".", tolower(type))
file <- sub("^(.*)[.].*", "\\1", file) # remove extension if given
file <- paste0(file, ext) # add extension
obj <- x
if (is.null(obj) & is.null(fun)) p = captureplot() else p = obj
if (inherits(p,"list"))
stop("base R plots cannot be passed as objects, use ggplot2 or lattice plots instead")
myplot = if (is.null(fun)) function(pl = p) print(pl) else fun
# Get graphical device information
if(!identical(options()$device, FALSE)){
plotsize = dev.size()
} else {
plotsize = c(7,5) # default device size: 10 inch x 10 inch
}
w <- plotsize[[1]]
h <- plotsize[[2]]
plotaspectr <- plotsize[[1]] / plotsize[[2]]
if ( !is.null(aspectr) & is.null(height) & is.null(width)) {
plotaspectr <- aspectr
if (plotaspectr >= 1) { h <- w / plotaspectr } else { w <- h * plotaspectr }
}
if ((is.null(height))&(!is.null(width))) { w = width; h = w / plotaspectr }
if ((is.null(width))&(!is.null(height))) { h = height; w = h / plotaspectr }
# if width and height is given override other scaling params
if ((!is.null(width))&(!is.null(height))) { w = width; h = height }
w = w*scaling/100; h = h*scaling/100;
if (type == "PNG") {
png( filename = file,
type = ifelse(cairo,"cairo-png","windows"),
units = "in",
width = w,
height = h,
family = font,
res = dpi,
bg = bg, ...)
myplot()
dev.reset(dev.init)
}
if (type == "TIF") {
tiff( filename = file,
type = ifelse(cairo,"cairo","windows"),
compression = tiffcompression,
units = "in",
width = w,
height = h,
family = font,
res = dpi,
bg = bg, ...)
myplot()
dev.reset(dev.init)
}
if (type == "JPEG") {
jpeg(filename = file,
quality = jpegquality,
units = "in",
width = w,
height = h,
res = dpi,
bg = bg, ...)
myplot()
dev.reset(dev.init)
}
message(paste0("Exported graph as ",file))
}
#' @describeIn graph2bitmap
#' Save currently active R graph to png file
#' @export
graph2png = function(...) graph2bitmap(type = "PNG", ...)
#' @describeIn graph2bitmap
#' Save currently active R graph to TIF file
#' @export
graph2tif = function(...) graph2bitmap(type = "TIF", ...)
#' @describeIn graph2bitmap
#' Save currently active R graph to JPEG file
#' @export
graph2jpg = function(...) graph2bitmap(type = "JPG", ...)
================================================
FILE: R/graph2office.R
================================================
#' Save currently active R graph to Microsoft Office / LibreOffice format
#'
#' Save the currently active R graph or a graph passed as an object or function
#' to Microsoft Office / LibreOffice format with sensible defaults
#'
#' @import datasets
#' @importFrom grDevices dev.size png
#' @importFrom devEMF emf
#' @importFrom utils head tail
#' @import officer
#' @import rvg
#'
#' @aliases graph2office graph2doc graph2ppt
#'
#' @param x given \code{ggplot2} plot or \code{lattice} plot object to export; if
#' set to \code{NULL} the currently active R graph will be exported; not
#' supported for base R plots.
#' @param file name of output file. Any extension is ignored and added
#' according to the requested output type.
#' @param fun plot passed on as a function used to create it; useful especially
#' for base R plots.
#' @param type desired output type - \code{DOC} for Word document, \code{PPT} for Powerpoint.
#' @param append logical value - if \code{TRUE} and \code{type=PPT} it will append the graph
#' to the given file, where file can also be a given corporate template. If
#' \code{append=FALSE} any existing file will be overwritten. Currently ignored in
#' Word export.
#' @param aspectr desired width to height aspect ratio. If set to \code{NULL}, the
#' aspect ratio of the active graphics device is used.
#' @param width desired width in inches; can be combined with a desired
#' aspect ratio aspectr.
#' @param height desired height in inches; can be combined with a desired
#' aspect ratio aspectr.
#' @param scaling scale width & height by a certain percentage.
#' @param paper desired paper size to use - "A5" to "A1" for Powerpoint export,
#' or "A5" to "A3" for Word output; default "auto" automatically selects the
#' paper size that fits your graph. Graphs that are too large to fit on a given
#' paper size are scaled down.
#' @param orient desired paper orientation - "auto", "portrait" or "landscape";
#' default to "auto" for Word output and to "landscape" for Powerpoint.
#' @param margins vector with the desired margins that should be left blank in
#' @param center logical specifying whether or not to center the graph
#' in the exported Powerpoint.
#' @param offx if center is set to \code{FALSE}, the desired x offset at which to
#' place one's graph in Powerpoint output.
#' @param offy if center is set to \code{FALSE}, the desired y offset at which to
#' place one's graph in Powerpoint output.
#' @param upscale logical specifying whether or not to upscale one's graph to
#' make it page-filling (excluding the margins). Note that scaling may result
#' in a different look of one's graph relative to how it looks on the screen
#' due to the change in size.
#' @param vector.graphic logical specifying whether or not to output in
#' vectorized format. This avoids pixelated images in the document. Note that
#' for PowerPoint, the image can be edited after first ungrouping the plot
#' elements. If set to \code{FALSE}, the plot is rasterized to \code{PNG} bitmap
#' format at a resolution of 300 dpi.
#' @param \dots any other options are passed on to \code{rvg}'s
#' \code{\link[rvg]{dml_pptx}} function if \code{type == "DOC"} or to
#' \code{devEMF}'s \code{\link[devEMF]{emf}} function if \code{type == "PPT"} (only
#' when \code{vector.graphics == TRUE}).
#'
#' @return No return value
#'
#' @author Tom Wenseleers, Christophe Vanderaa
#'
#' @example examples/graph2office.R
#'
#' @seealso \code{\link{graph2vector}}, \code{\link{graph2svg}}, \code{\link{graph2pdf}}, \code{\link{graph2eps}},
#' \code{\link{graph2bitmap}}, \code{\link{graph2png}}, \code{\link{graph2tif}}, \code{\link{graph2jpg}}
#'
#' @export
#'
graph2office = function(x = NULL, file = "Rplot", fun = NULL, type = c("PPT","DOC"),
append = FALSE, aspectr = NULL, width = NULL, height = NULL, scaling=100,
paper = "auto", orient = ifelse(type[1]=="PPT","landscape","auto"),
margins = c(top=0.5,right=0.5,bottom=0.5,left=0.5),
center = TRUE, offx = 1, offy = 1, upscale = FALSE,
vector.graphic = TRUE,
...) {
### 1. Check and format arguments
margins=rep_len(margins,4)
names(margins)=c("top","right","bottom","left")
type = toupper(type)
type = match.arg(type, c("PPT", "DOC"))
if (type == "PPT" | type == "PPTX") {
ext = ".pptx"
type = "PPT"
}
if (type == "DOC" | type == "DOCX") {
ext = ".docx"
type = "DOC"
}
file = sub("^(.*)[.].*", "\\1", file) # remove extension if given
file = paste0(file, ext) # add extension
# Format the function call for plotting the graph
obj = x
if (is.null(obj) && is.null(fun)) {
p = captureplot()
} else {
p = obj
}
if (inherits(p,"list")) { stop("base R plots cannot be passed as objects, use ggplot2 or lattice plots instead") }
myplot = if (is.null(fun)){
function(pl = p) print(pl)
} else {
fun
}
### 2. Prepare the plotting region and the plot apsect
if ((!is.null(width))&&(!is.null(height))) {
# if width and height is given
w = width;
h = height;
plotaspectr = w/h
} else {
# infer width and height
if(!identical(options()$device, FALSE)){
plotsize = dev.size()
} else {
plotsize = c(7,5) # default device size: 10 inch x 10 inch
}
w = plotsize[[1]]
h = plotsize[[2]]
plotaspectr = plotsize[[1]]/plotsize[[2]]
if ((!is.null(aspectr))&is.null(height)&is.null(width)) {
plotaspectr = aspectr
if (plotaspectr >= 1) {
h = w/plotaspectr
} else {
w = h*plotaspectr
}
}
if ((is.null(height))&(!is.null(width))) { plotaspectr = aspectr; w = width; h = w / plotaspectr }
if ((is.null(width))&(!is.null(height))) { plotaspectr = aspectr; h = height; w = h / plotaspectr }
}
w = w*scaling/100; h = h*scaling/100;
### 3. Find the best template (docx or pptx) to contain the plot
# if paper="auto" choose template with best fitting size
if (append & file.exists(file)) {
templ=file
} else {
if(paper=="auto") {
templ=besttemplate(w=w,h=h,margins=margins,orient=orient,type=type)
#templ=paste0(paste( find.package("export"), "inst", "templates",templ, sep = "/" ),ext)
templ=paste0(paste( find.package("export"), "templates",templ, sep = "/" ),ext)
} else {
templ=paste( find.package("export"), "templates",paste0(toupper(paper),"_",orient,ext), sep = "/" )
if (!file.exists(templ)) stop(paste0("template ",templ," not available"))
}
}
### 4. Initialize the slide (ppt) or page (doc) that will contain the plot
if (type == "PPT") {
if (append & file.exists(file)){
doc <- read_pptx(path = file)
} else {
doc <- read_pptx(path = templ)
}
doc = add_slide(doc, layout = "Blank", master = "Office Theme")
pagesize = get.slide.size(doc)
pagesize["width"]=pagesize["width"]-(margins["left"]+margins["right"])
pagesize["height"]=pagesize["height"]-(margins["top"]+margins["bottom"])
}
if (type == "DOC") {
if (append & file.exists(file)){
doc <- read_docx(path = file)
doc <- body_add_break(doc, pos = "after")
} else {
doc <- read_docx(path = templ)
}
pagesize <- (doc$sect_dim$page - doc$sect_dim$margins[c(3,2)])/1440 # 1440 is a factor to convert to inches
}
### 5. Scale the plot according to the new slide or page
# should graph still be shrinked to fit or upscaled?
if ((w>pagesize["width"])|(h>pagesize["height"])) shrink=TRUE else shrink=FALSE
if (shrink|upscale) {
pageaspectr = pagesize["width"]/pagesize["height"]
if (pageaspectr >= plotaspectr) {
xf = plotaspectr/pageaspectr
yf = 1
} else {
xf = 1
yf = pageaspectr/plotaspectr
}
w = pagesize["width"] * xf
h = pagesize["height"] * yf
}
### 6. Print the plot on the slide or page
if(type=="PPT"){
if (center) {
offx = (pagesize["width"] + margins["left"]+margins["right"] - w)/2
offy = (pagesize["height"] + margins["top"]+margins["bottom"] - h)/2
}
if(vector.graphic){
doc = ph_with(doc, dml(code = myplot()),
location = ph_location(left = offx, top = offy, width = w,
height = h), ...)
} else {
temp.file <- paste0(tempfile(), ".png")
grDevices::png(filename = temp.file, height = h, width = w, units = "in", res = 300)
myplot()
dev.off()
doc <- ph_with(doc, external_img(src = temp.file), location = ph_location(left = offx, top = offy, width = w, height = h))
unlink(temp.file)
}
} else {
temp.file <- tempfile()
if(vector.graphic){
temp.file <- paste0(temp.file, ".emf")
emf(file = temp.file, height = h, width = w, emfPlus = TRUE, ...)
myplot()
} else {
temp.file <- paste0(temp.file, ".png")
grDevices::png(filename = temp.file, height = h, width = w, units = "in", res = 300)
myplot()
}
dev.off()
doc <- body_add_img(doc, src = temp.file, width = w, height = h)
unlink(temp.file)
}
### 7. End of function, save the file and print message
print(doc, target = file)
message(paste0("Exported graph as ",file))
}
#' @describeIn graph2office
#' Save currently active R graph to a Microsoft Office PowerPoint/LibreOffice Impress presentation
#' @export
graph2ppt = function(...) graph2office(type = "PPT", ...)
#' @describeIn graph2office
#' Save currently active R graph to a Microsoft Office Word/LibreOffice Writer document
#' @export
graph2doc = function(...) graph2office(type = "DOC", ...)
================================================
FILE: R/graph2vector.R
================================================
#' Save currently active R graph to vector format
#'
#' Save the currently active R graph or a graph passed as an object or function
#' to vector format with sensible defaults
#'
#'
#' @importFrom grDevices dev.size
#' @importFrom grDevices svg
#' @importFrom grDevices pdf
#' @importFrom grDevices postscript
#' @importFrom grDevices dev.off
#' @importFrom grDevices cairo_pdf
#' @importFrom grDevices cairo_ps
#' @aliases graph2vector graph2svg graph2pdf graph2eps
#' @param x given \code{ggplot2} plot or \code{lattice} plot object to export; if
#' set to \code{NULL} the currently active R graph will be exported; not
#' supported for base R plots.
#' @param file name of output file. Any extension is ignored and added
#' according to the requested output type. If file already exists it is overwritten.
#' @param fun plot passed on as a function used to create it; useful especially
#' for base R plots.
#' @param type desired output type - \code{SVG}, \code{PDF} or \code{EPS} are currently supported.
#' \code{SVG} is the preferred format, and good for editing in Inkscape; \code{PDF} is good
#' for printing; \code{EPS} is sometimes requested by journals, though lower quality,
#' especially when semi-transparency is used, as this is rasterized to bitmap.
#' \code{\link{graph2office}} is recommended for vector output to Microsoft Office.
#' @param aspectr desired width to height aspect ratio. If set to \code{NULL}, the
#' aspect ratio of the graphics device is used. Can also be combined with one
#' value for either the desired width or height of the graph.
#' @param width desired width in inches; can be combined with a desired
#' aspect ratio aspectr.
#' @param height desired height in inches; can be combined with a desired
#' aspect ratio aspectr.
#' @param scaling scale width & height by a certain percentage.
#' @param font desired font to use for labels; defaults to \code{"Arial"} on Windows
#' systems and to \code{"Helvetica"} on other systems. Fonts are embedded by default in \code{EPS} output.
#' @param bg desired background colour, e.g. \code{"white"} or \code{"transparent"}.
#' @param cairo logical indicating whether or not to use the \code{cairo} graphics
#' device for output to \code{PDF} or \code{EPS}, defaults to \code{TRUE}, thereby allowing for
#' simulated semi-transparency in \code{EPS} output, by rasterizing semi-transparent
#' sections, and automated font embedding.
#' @param fallback_resolution resolution in dpi to use to rasterize non-supported
#' vector graphics (e.g. semi-transparent vector elements in \code{EPS}) output).
#' @param colormodel desired colormodel in \code{pdf} or \code{eps} output when \code{cairo=FALSE};
#' currently allowed values are \code{"rgb"} (default), \code{"cmyk"}, \code{"srgb"}, \code{"srgb+gray"}, \code{"rgb-nogray"},
#' and \code{"gray"} (or \code{"grey"}).
#' @param \dots any other options are passed on to \code{\link{svg}}, \code{\link{cairo_pdf}}, \code{\link{cairo_ps}}, \code{\link{pdf}} or
#' postscript.
#' @return No return value
#' @author Tom Wenseleers
#' @example examples/graph2vector.R
#' @seealso \code{\link{graph2office}}, \code{\link{graph2bitmap}}, \code{\link{graph2png}}, \code{\link{graph2tif}}, \code{\link{graph2jpg}}
#' @export
#'
graph2vector = function(x = NULL, file = "Rplot", fun = NULL, type = "SVG",
aspectr = NULL, width = NULL, height = NULL, scaling = 100,
font = ifelse(Sys.info()["sysname"]=="Windows","Arial",
"Helvetica")[[1]], bg = "white", colormodel="rgb",
cairo = TRUE, fallback_resolution = 600, ...) {
type = toupper(type)
type = match.arg(type,c("SVG","PDF","EPS"))
ext = paste0(".", tolower(type))
file = sub("^(.*)[.].*", "\\1", file) # remove extension if given
file = paste0(file, ext) # add extension
obj=x
if (is.null(obj) & is.null(fun)) p = captureplot() else p = obj
if (inherits(p,"list"))
stop("base R plots cannot be passed as objects, use ggplot2 or lattice plots instead")
myplot = if (is.null(fun)) function(pl = p) print(pl) else fun
if(!identical(options()$device, FALSE)){
plotsize = dev.size()
} else {
plotsize = c(7,5) # default device size: 10 inch x 10 inch
}
w = plotsize[[1]]
h = plotsize[[2]]
plotaspectr = plotsize[[1]]/plotsize[[2]]
if ((!is.null(aspectr))&is.null(height)&is.null(width)) { plotaspectr = aspectr
if (plotaspectr >= 1) {
h = w/plotaspectr } else { w = h*plotaspectr }
}
if ((is.null(height))&(!is.null(width))) { w = width; h = w / plotaspectr }
if ((is.null(width))&(!is.null(height))) { h = height; w = h / plotaspectr }
# if width and height is given override other scaling params
if ((!is.null(width))&(!is.null(height))) { w = width; h = height }
w = w*scaling/100; h = h*scaling/100;
if (type == "SVG") {
svg(filename = file,
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
... )
myplot()
dev.off()
}
if (type == "PDF") {
#cairo_surface_set_fallback_resolution() # check cairoSurfaceSetFallbackResolution in library(RGtk2)
if (!cairo) {
pdf(file = file, # also check cairo_pdf
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
colormodel = colormodel,
useDingbats = FALSE,
... )
} else {
if ("fallback_resolution" %in% names(formals(fun=cairo_ps))) {
cairo_pdf(filename = file,
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
fallback_resolution = fallback_resolution,
... )
} else {
cairo_pdf(filename = file, # also check cairo_pdf
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
... )
}
}
myplot()
dev.off()
}
if (type == "EPS") {
if (!cairo) { postscript(file = file,
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
colormodel = colormodel,
... )
} else {
if ("fallback_resolution" %in% names(formals(fun=cairo_ps))) {
cairo_ps(filename = file,
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
fallback_resolution = fallback_resolution,
... )
} else {
cairo_ps(filename = file,
height = h,
width = w,
family = font,
onefile = FALSE,
bg = bg,
... )
}
}
myplot()
dev.off()
}
message(paste0("Exported graph as ",file))
}
#' @describeIn graph2vector
#' Save currently active R graph to SVG format
#' @export
graph2svg = function(...) graph2vector(type = "SVG", ...)
#' @describeIn graph2vector
#' Save currently active R graph to PDF format
#' @export
graph2pdf = function(...) graph2vector(type = "PDF", ...)
#' @describeIn graph2vector
#' Save currently active R graph to EPS format
#' @export
graph2eps = function(...) graph2vector(type = "EPS", ...)
================================================
FILE: R/rgl2bitmap.R
================================================
#' Save currently active rgl 3D graph to bitmap format
#'
#' Save currently active rgl 3D graph to bitmap format in current orientation
#'
#'
#' @aliases rgl2bitmap rgl2png
#' @param file name of output file. Any extension is ignored and added
#' according to the requested output type. If file already exists it is overwritten.
#' @param type desired output type - currently only \code{PNG} is supported.
#' @param \dots passing the \code{rgl2png} arguments to \code{rgl2bitmap}
#' @return No return value
#' @author Tom Wenseleers
#' @example examples/rgl2bitmap.R
#' @export
#'
rgl2bitmap = function(file = "Rplot", type = c("PNG")) {
if ( ! requireNamespace("rgl", quietly = TRUE)) {
stop("Package 'rgl' is required for this function. Please install it.")
}
type = toupper(type)
type = match.arg(type)
ext = paste0(".", tolower(type))
file = sub("^(.*)[.].*", "\\1", file) # remove extension if given
file = paste0(file, ext) # add extension
if (rgl::rgl.cur()==0) stop("No rgl device open to capture plot from")
rgl::rgl.snapshot(file, fmt="png", top=TRUE)
message(paste0("Exported rgl graph as ",file))
}
#' @describeIn rgl2bitmap
#' Save currently active rgl 3D graph to PNG format
#' @export
rgl2png = function(...) rgl2bitmap(type = "PNG", ...)
================================================
FILE: R/table2office.R
================================================
#' Export statistical output to a table in Microsoft Office / LibreOffice format
#'
#' Export currently showing R stats object or stats object obj to a Microsoft
#' Office / LibreOffice table
#'
#' @importFrom utils methods
#' @import stats
#' @importFrom xtable xtable
#' @importFrom broom tidy
#' @import officer
#' @import flextable
#' @aliases table2office table2doc table2ppt
#' @param x given R stats object to export; if set to \code{NULL} the output of the
#' previous R command will be exported.
#' @param file name of output file. The .pptx or .docx extension is added automatically.
#' @param type desired output type - \code{"PPT"} for PowerPoint and \code{"DOC"} for Word.
#' @param append logical value - if \code{TRUE} and \code{type="PPT"} or \code{"DOC"} it will
#' append the table to the given file, where file can also be a given corporate. If
#' \code{append=FALSE} any existing file will be overwritten.
#' @param digits number of digits after the comma (for all numeric columns
#' except p-values or degrees of freedom)
#' @param digitspvals number of digits after the comma (for p-values only). The
#' default is equal to \code{digits}.
#' @param trim.pval a threshold below which the p-values are trimmed as
#' "< \code{trim.pval}".
#' @param 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.
#' @param 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.
#' @param offx x offset in inches to specify horizontal location of table (only for \code{type=="PPT"}).
#' @param offy y offset in inches to specify vertical location of table (only for \code{type=="PPT"}).
#' @param font desired font to use for output table; defaults to \code{"Arial"} on Windows
#' systems and to \code{"Helvetica"} on other systems.
#' @param pointsize desired font point size.
#' @param add.rownames logical specifying whether or not to add row names.
#' @param \dots Further arguments to be passed to \code{table2office}.
#' @return \code{\link[flextable]{flextable}} object
#' @details Columns corresponding to degrees of freedom (with header "Df" or "df")
#' are always given as integers. Objects that can be exported with \code{\link{table2office}} are
#' all those supported by \code{\link[xtable]{xtable}} and \code{\link[broom]{tidy}}. The function will
#' first use \code{\link[xtable]{xtable}} to format the data. If the data class is not supported by
#' \code{\link[xtable]{xtable}} the function will then use \code{\link[broom]{tidy}}.
#' The data classes suported by \code{\link[xtable]{xtable}} are:
#' \itemize{
#' \item \code{anova}
#' \item \code{aov}
#' \item \code{aovlist}
#' \item \code{data.frame}
#' \item \code{glm}
#' \item \code{gmsar}
#' \item \code{lagImpact}
#' \item \code{lm}
#' \item \code{matrix}
#' \item \code{prcomp}
#' \item \code{sarlm}
#' \item \code{sarlm.pred}
#' \item \code{spautolm}
#' \item \code{sphet}
#' \item \code{splm}
#' \item \code{stsls}
#' \item \code{summary.aov}
#' \item \code{summary.aovlist}
#' \item \code{summary.glm}
#' \item \code{summary.gmsar}
#' \item \code{summary.lm}
#' \item \code{summary.prcomp}
#' \item \code{summary.sarlm}
#' \item \code{summary.spautolm}
#' \item \code{summary.sphet}
#' \item \code{summary.splm}
#' \item \code{summary.stsls}
#' \item \code{table}
#' \item \code{ts}
#' \item \code{zoo}
#' }
#' The data classes suported by \code{\link[broom]{tidy}} are:
#' \itemize{
#' \item \code{aareg}
#' \item \code{acf}
#' \item \code{Arima}
#' \item \code{betareg}
#' \item \code{biglm}
#' \item \code{binDesign}
#' \item \code{binWidth}
#' \item \code{brmsfit}
#' \item \code{btergm}
#' \item \code{cch}
#' \item \code{character}
#' \item \code{cld}
#' \item \code{coeftest}
#' \item \code{confint.glht}
#' \item \code{cv.glmnet}
#' \item \code{default}
#' \item \code{density}
#' \item \code{dgCMatrix}
#' \item \code{dgTMatrix}
#' \item \code{dist}
#' \item \code{emmGrid}
#' \item \code{ergm}
#' \item \code{felm}
#' \item \code{fitdistr}
#' \item \code{ftable}
#' \item \code{gam}
#' \item \code{Gam}
#' \item \code{gamlss}
#' \item \code{geeglm}
#' \item \code{glht}
#' \item \code{glmnet}
#' \item \code{glmRob}
#' \item \code{gmm}
#' \item \code{htest}
#' \item \code{ivreg}
#' \item \code{kappa}
#' \item \code{kde}
#' \item \code{kmeans}
#' \item \code{Line}
#' \item \code{Lines}
#' \item \code{list}
#' \item \code{lme}
#' \item \code{lmodel2}
#' \item \code{lmRob}
#' \item \code{logical}
#' \item \code{lsmobj}
#' \item \code{manova}
#' \item \code{map}
#' \item \code{Mclust}
#' \item \code{merMod}
#' \item \code{mle2}
#' \item \code{muhaz}
#' \item \code{multinom}
#' \item \code{nlrq}
#' \item \code{nls}
#' \item \code{NULL}
#' \item \code{numeric}
#' \item \code{orcutt}
#' \item \code{pairwise.htest}
#' \item \code{plm}
#' \item \code{poLCA}
#' \item \code{Polygon}
#' \item \code{Polygons}
#' \item \code{power.htest}
#' \item \code{pyears}
#' \item \code{rcorr}
#' \item \code{ref.grid}
#' \item \code{ridgelm}
#' \item \code{rjags}
#' \item \code{roc}
#' \item \code{rowwise_df}
#' \item \code{rq}
#' \item \code{rqs}
#' \item \code{sparseMatrix}
#' \item \code{SpatialLinesDataFrame}
#' \item \code{SpatialPolygons}
#' \item \code{SpatialPolygonsDataFrame}
#' \item \code{spec}
#' \item \code{speedlm}
#' \item \code{stanfit}
#' \item \code{stanreg}
#' \item \code{summary.glht}
#' \item \code{summaryDefault}
#' \item \code{survdiff}
#' \item \code{survexp}
#' \item \code{survfit}
#' \item \code{survreg}
#' \item \code{tbl_df}
#' \item \code{TukeyHSD}
#' }
#' @author Tom Wenseleers, Christophe Vanderaa
#' @example examples/table2office.R
#' @seealso \code{\link{table2tex}}, \code{\link{table2html}}, \code{\link{table2spreadsheet}}
#' @export
#'
table2office = function(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) {
if(is.null(digitspvals)) digitspvals <- digits
obj=x
if (is.null(obj)) {
outp = .Last.value # capture previously shown output or use passed object
} else {
outp = obj
}
if (is.null(outp)) stop("no R stats object available to export")
supobjects = unique(c(as.character(gsub("xtable.", "", methods(xtable))),
as.character(gsub("tidy.", "", methods(tidy))),
"xtabs"))
if (length(intersect(class(outp), supobjects)) == 0) stop(paste0(class(outp), " is currently not supported by table2office"))
type=toupper(type)
type=match.arg(type,c("PPT","DOC"))
ext <- if(type=="PPT"){
".pptx"
} else if(type == "DOC"){
".docx"
}
file = sub("^(.*)[.].*", "\\1", file) # remove extension if given
file = paste0(file, ext) # add extension
if(type == "PPT"){
if (append & file.exists(file)) {
doc = read_pptx(path = file)
} else {
doc = read_pptx()
}
doc <- add_slide(doc, layout = "Blank", master = "Office Theme")
pagesize <- get.slide.size(doc)
} else if(type == "DOC"){
if (append & file.exists(file)) {
doc = read_docx(path = file)
doc = body_add_break(doc, pos = "after")
} else {
doc = read_docx()
}
pagesize <- (doc$sect_dim$page - doc$sect_dim$margins[c(3,2)])/1440 # 1440 is a factor to convert to inches
}
# deal with specific classes of objects
if (inherits(outp, "summary.merMod")) {
outp <- data.frame(coef(summary(outp)), check.names = F)
} else if(inherits(outp, "Matrix")) {
outp <- as.data.frame(as.matrix(x))
} else if (inherits(outp, c("xtabs", "ftable"))) {
outp <- ftable(outp)
}
# Depending on the data class, call xtable or tidy
if (length(intersect(class(outp), as.character(gsub("xtable.", "", methods(xtable))))) >= 1) {
tab <- xtable2(x=outp, ndigits = digits, ndigitspvals = digitspvals, trim.pval = trim.pval)
} else if (length(intersect(class(outp), as.character(gsub("tidy.", "", methods(tidy))))) >= 1) {
tab <- tidy2(x=outp, ndigits = digits, ndigitspvals = digitspvals, trim.pval = trim.pval)
} else { # should not occur
tab <- data.frame2(x=outp, ndigits = digits, ndigitspvals = digitspvals, trim.pval = trim.pval)
}
nc <- ncol(tab)
nr <- nrow(tab)
tblaspectr = nc / nr * 2 # guess table aspect ratio
pageaspectr = pagesize["width"]/pagesize["height"]
if (pageaspectr > tblaspectr) {
xf = tblaspectr/pageaspectr
yf = 1
} else {
xf = 1
yf = pageaspectr/tblaspectr
}
w = pagesize["width"] * xf
h = pagesize["height"] * yf
# if width and height is given override other scaling params
if (!is.null(width)) w = width
if (!is.null(height)) h = height
# Avoid bug in flextable: when one of the colnames = x, flextable returns an empty table
x.col <- which(colnames(tab) == "x")
if(length(x.col)>0) colnames(tab)[x.col]<- "x "
# Issues
# - Deal with ftable
# - use margins ?
cell.height <- min(h, pagesize["height"] - offy)/(nr+1)
cell.width <- min(w, pagesize["width"] - offx)/(nc+1)
if(inherits(tab,"xtable")){
tab <- as_flextable(tab, include.rownames = add.rownames, rowname_col = ".")
tab <- width(tab, width=cell.width)
tab <- height(tab, height=cell.height)
} else {
if(add.rownames) x <- cbind(" " = rownames(x), x)
tab <- flextable(tab, cheight = cell.height, cwidth = cell.width)
}
# Format the digits
col.pval <- grep("\\QPr(\\E|\\Qp-value\\E|\\Qp value\\E|\\Qpadj\\E|^p$|^padj$|p[.]value", tab$col_keys, value = TRUE)
col.df <- grep("^df$", tab$col_keys, value = TRUE, ignore.case = TRUE)
col.other <- tab$col_keys[! tab$col_keys %in% c(col.pval, col.df)]
tab <- colformat_double(x = tab, j = col.other, digits = digits)
tab <- colformat_int(x = tab, j = col.df)
tab <- colformat_double(x = tab, j = col.pval)
tab <- bold(tab, part = "header") # bold header
tab <- fontsize(tab, part = "all", size = pointsize)
tab <- font(tab, part = "all", fontname = font)
if(type=="PPT"){
doc <- ph_with(doc, value = tab , location = ph_location(left = offx, top = offy))
} else if(type == "DOC"){
doc <- body_add_flextable(doc, value = tab)
}
print(doc, target = file)
message(paste0("Exported table as ",file))
return(tab)
}
#' @describeIn table2office
#' Export statistical output to a table in a Microsoft Office PowerPoint/ LibreOffice Impress presentation
#' @export
table2ppt = function(...) table2office(type = "PPT", ...)
#' @describeIn table2office
#' Export statistical output to a table in a Microsoft Office Word/ LibreOffice Writer document
#' @export
table2doc = function(...) table2office(type = "DOC", ...)
================================================
FILE: R/table2spreadsheet.R
================================================
#' Export statistical output to a table in spreadsheet compatible format (.xlsx or .csv)
#'
#' Export currently showing R stats object or stats object obj to a Microsoft Excel /
#' LibreOffice Calc or comma-separated value file
#'
#' @importFrom utils methods write.csv write.csv2
#' @import stats
#' @import openxlsx
#' @importFrom xtable xtable
#' @aliases table2spreadsheet table2excel table2csv table2csv2
#' @param x given R stats object to export; if set to \code{NULL} the output of the
#' previous R command will be exported.
#' @param file name of output file. The .xlsx or .csv extension is added automatically.
#' @param type desired output type - \code{"XLS"} for Excel and \code{"CSV"}/\code{"CSV2"} for CSV file. Note that
#' \code{type="CSV2"} will generate a CSV file where the value separator is a semi-colon (";") and the decimal
#' separator is a comma (",")
#' @param append logical value - if \code{TRUE} and \code{type="XLS"} it will add a new woorksheet to the given
#' file, where file can also be a given corporate.
#' \code{append=FALSE} any existing file will be overwritten.
#' @param sheetName a string giving the name of the new sheet that is created (only for \code{type=="XLS"}).
#' It must be unique (case insensitive) from any existing sheet name in the file.
#' @param digits number of significant digits to show for all columns except
#' for the column with p values.
#' @param digitspvals number of significant digits to show for columns with p
#' values.
#' @param trim.pval a threshold below which the p-values are trimmed as
#' "< \code{trim.pval}".
#' @param add.rownames logical specifying whether or not to add row names.
#' @param \dots extra options are passed on to \code{\link[openxlsx]{createStyle}} for the formatting of the woorksheet.
#' This is only applicable for \code{type=="XLS"}.
# #' @return \code{\link[flextable]{flextable}} object
#' @return A data frame
#' @details Columns corresponding to degrees of freedom (with header "Df" or "df")
#' are always given as integers. Objects that can be exported with \code{\link{table2office}} are
#' all those supported by \code{\link[xtable]{xtable}} and \code{\link[broom]{tidy}}. The function will
#' first use \code{\link[xtable]{xtable}} to format the data. If the data class is not supported by
#' \code{\link[xtable]{xtable}} the function will then use \code{\link[broom]{tidy}}.
#' The data classes suported by \code{\link[xtable]{xtable}} are:
#' \itemize{
#' \item \code{anova}
#' \item \code{aov}
#' \item \code{aovlist}
#' \item \code{data.frame}
#' \item \code{glm}
#' \item \code{gmsar}
#' \item \code{lagImpact}
#' \item \code{lm}
#' \item \code{matrix}
#' \item \code{prcomp}
#' \item \code{sarlm}
#' \item \code{sarlm.pred}
#' \item \code{spautolm}
#' \item \code{sphet}
#' \item \code{splm}
#' \item \code{stsls}
#' \item \code{summary.aov}
#' \item \code{summary.aovlist}
#' \item \code{summary.glm}
#' \item \code{summary.gmsar}
#' \item \code{summary.lm}
#' \item \code{summary.prcomp}
#' \item \code{summary.sarlm}
#' \item \code{summary.spautolm}
#' \item \code{summary.sphet}
#' \item \code{summary.splm}
#' \item \code{summary.stsls}
#' \item \code{table}
#' \item \code{ts}
#' \item \code{zoo}
#' }
#' The data classes suported by \code{\link[broom]{tidy}} are:
#' \itemize{
#' \item \code{aareg}
#' \item \code{acf}
#' \item \code{Arima}
#' \item \code{betareg}
#' \item \code{biglm}
#' \item \code{binDesign}
#' \item \code{binWidth}
#' \item \code{brmsfit}
#' \item \code{btergm}
#' \item \code{cch}
#' \item \code{character}
#' \item \code{cld}
#' \item \code{coeftest}
#' \item \code{confint.glht}
#' \item \code{cv.glmnet}
#' \item \code{default}
#' \item \code{density}
#' \item \code{dgCMatrix}
#' \item \code{dgTMatrix}
#' \item \code{dist}
#' \item \code{emmGrid}
#' \item \code{ergm}
#' \item \code{felm}
#' \item \code{fitdistr}
#' \item \code{ftable}
#' \item \code{gam}
#' \item \code{Gam}
#' \item \code{gamlss}
#' \item \code{geeglm}
#' \item \code{glht}
#' \item \code{glmnet}
#' \item \code{glmRob}
#' \item \code{gmm}
#' \item \code{htest}
#' \item \code{ivreg}
#' \item \code{kappa}
#' \item \code{kde}
#' \item \code{kmeans}
#' \item \code{Line}
#' \item \code{Lines}
#' \item \code{list}
#' \item \code{lme}
#' \item \code{lmodel2}
#' \item \code{lmRob}
#' \item \code{logical}
#' \item \code{lsmobj}
#' \item \code{manova}
#' \item \code{map}
#' \item \code{Mclust}
#' \item \code{merMod}
#' \item \code{mle2}
#' \item \code{muhaz}
#' \item \code{multinom}
#' \item \code{nlrq}
#' \item \code{nls}
#' \item \code{NULL}
#' \item \code{numeric}
#' \item \code{orcutt}
#' \item \code{pairwise.htest}
#' \item \code{plm}
#' \item \code{poLCA}
#' \item \code{Polygon}
#' \item \code{Polygons}
#' \item \code{power.htest}
#' \item \code{pyears}
#' \item \code{rcorr}
#' \item \code{ref.grid}
#' \item \code{ridgelm}
#' \item \code{rjags}
#' \item \code{roc}
#' \item \code{rowwise_df}
#' \item \code{rq}
#' \item \code{rqs}
#' \item \code{sparseMatrix}
#' \item \code{SpatialLinesDataFrame}
#' \item \code{SpatialPolygons}
#' \item \code{SpatialPolygonsDataFrame}
#' \item \code{spec}
#' \item \code{speedlm}
#' \item \code{stanfit}
#' \item \code{stanreg}
#' \item \code{summary.glht}
#' \item \code{summaryDefault}
#' \item \code{survdiff}
#' \item \code{survexp}
#' \item \code{survfit}
#' \item \code{survreg}
#' \item \code{tbl_df}
#' \item \code{TukeyHSD}
#' }
#' @author Tom Wenseleers, Christophe Vanderaa
#' @example examples/table2spreadsheet.R
#' @seealso \code{\link{table2tex}}, \code{\link{table2html}}, \code{\link{table2office}}
#' @export
#'
table2spreadsheet = function(x = NULL, file = "Rtable", type = c("XLS","CSV","CSV2"), append = FALSE, sheetName="new sheet",
digits = 2, digitspvals = 2, trim.pval = 1E-16, add.rownames = FALSE, ...) {
obj=x
if (is.null(obj)) {
outp = .Last.value # capture previously shown output or use passed object
} else {
outp = obj
}
if (is.null(outp)) stop("no R stats object available to export")
supobjects = unique(c(as.character(gsub("xtable.", "", methods(xtable))),
as.character(gsub("tidy.", "", methods(tidy))),
"xtabs"))
if (length(intersect(class(outp), supobjects)) == 0) stop(paste0(class(outp), " is currently not supported by table2office"))
type=toupper(type)
type=match.arg(type,c("XLS","CSV"))
ext <- if(type=="XLS"){
".xlsx"
} else if(type == "CSV" || type == "CSV2"){
".csv"
}
file = sub("^(.*)[.].*", "\\1", file) # remove extension if given
file = paste0(file, ext) # add extension
# deal with specific classes of objects
if (inherits(outp, "summary.merMod")) {
outp <- data.frame(coef(summary(outp)), check.names = F)
} else if(inherits(outp, "Matrix")) {
outp <- as.data.frame(as.matrix(x))
} else if (inherits(outp, c("xtabs", "ftable"))) {
outp <- ftable(outp)
}
# Depending on the data class, call xtable or tidy
if (length(intersect(class(outp), as.character(gsub("xtable.", "", methods(xtable))))) >= 1) {
tab <- xtable2(x=outp, ndigits = digits, ndigitspvals = digitspvals, trim.pval=trim.pval)
} else if (length(intersect(class(outp), as.character(gsub("tidy.", "", methods(tidy))))) >= 1) {
tab <- tidy2(x=outp, ndigits = digits, ndigitspvals = digitspvals, trim.pval=trim.pval)
} else { # should not occur
tab <- data.frame2(x=outp, ndigits = digits, ndigitspvals = digitspvals, trim.pval=trim.pval)
}
if(type=="XLS"){
if (append & file.exists(file)){
doc <- loadWorkbook(file=file)
} else {
doc <- createWorkbook()
}
addWorksheet(doc, sheetName = sheetName)
writeData(doc, sheet = sheetName, x = tab, colNames = TRUE, rowNames = add.rownames,
headerStyle = createStyle(textDecoration="bold"), withFilter = FALSE)
sheetStyle <- createStyle(...)
addStyle(doc, sheet = sheetName, style = sheetStyle,
rows = rep(2:(nrow(tab)+1), ncol(tab)),
cols = rep((1+add.rownames):(ncol(tab)+add.rownames), each=nrow(tab)))
saveWorkbook(doc, file, overwrite = TRUE)
} else if(type == "CSV"){
write.csv(x=tab, file=file, quote=F, row.names = add.rownames)
} else if(type == "CSV2"){
write.csv2(x=tab, file=file, quote=F, row.names = add.rownames)
}
message(paste0("Exported table as ",file))
return(as.data.frame(tab))
}
#' @describeIn table2spreadsheet
#' Export statistical output to a table in a Microsoft Office Excel/ LibreOffice Calc spreadsheet
#' @export
table2excel <- function(...) table2spreadsheet(..., type = "XLS")
#' @describeIn table2spreadsheet
#' Export statistical output to a table in a CSV format ("," for value separation and "." for decimal)
#' @export
table2csv <- function(...) table2spreadsheet(..., type = "CSV")
#' @describeIn table2spreadsheet
#' Export statistical output to a table in a CSV format (";" for value separation and "," for decimal)
#' @export
table2csv2 <- function(...) table2spreadsheet(..., type = "CSV2")
================================================
FILE: R/table2tex.R
================================================
#' Export statistical output to HTML or Latex table
#'
#' Export currently showing R stats object or stats object obj to a
#' HTML or Latex table
#' @import stats
#' @importFrom utils capture.output
#' @import stargazer
#' @aliases table2tex table2html
#' @param x given R stats object or list of stats objects to export; if set to \code{NULL}
#' the output of the previous R command will be exported.
#' @param file name of output file. The appropriate extension is added automatically.
#' @param type desired output type - \code{"TEX"} for Latex and \code{"HTML"} for HTML.
#' @param digits number of significant digits to show for all columns except
#' for the column with p values.
#' @param digitspvals number of significant digits to show for columns with p
#' values.
#' @param trim.pval a threshold below which the p-values are trimmed as
#' "< \code{trim.pval}".
#' @param summary logical indicating whether or not to summarize data files.
#' @param standAlone logical indicating whether exported Latex code should be
#' standalone compilable, or whether it will be pasted into another document.
#' @param add.rownames logical indicating whether the names of the rows should be added
#' to the table (inserting a column before first column).
#' @param \dots extra options are passed on to stargazer.
#' @return No return value
#' @details Objects that can be exported are all those supported by \code{\link[xtable]{xtable}},
#' \code{\link[broom]{tidy}} (see \code{\link{table2office}} for an extensive list of supported
#' methods), or \code{\link[stargazer]{stargazer}}. The models supported by
#' \code{\link[stargazer]{stargazer}} are:
#' \itemize{
#' \item \code{aftreg} (\code{eha})
#' \item \code{anova} (\code{stats})
#' \item \code{aov} (\code{stats})
#' \item \code{aovlist} (\code{stats})
#' \item \code{arima} (\code{stats})
#' \item \code{betareg} (\code{betareg})
#' \item \code{binaryChoice} (\code{sampleSelection})
#' \item \code{bj} (\code{rms})
#' \item \code{brglm} (\code{brglm})
#' \item \code{censReg} (\code{censReg})
#' \item \code{coeftest} (\code{lmtest})
#' \item \code{coxph} (\code{survival})
#' \item \code{coxreg} (\code{eha})
#' \item \code{clm} (\code{ordinal})
#' \item \code{clogit} (\code{survival})
#' \item \code{cph} (\code{rms})
#' \item \code{dynlm} (\code{dynlm})
#' \item \code{ergm} (\code{ergm})
#' \item \code{errorsarlm} (\code{spdev})
#' \item \code{felm} (\code{lfe})
#' \item \code{gam} (\code{mgcv})
#' \item \code{garchFit} (\code{fGarch})
#' \item \code{gee} (\code{gee})
#' \item \code{glm} (\code{stats})
#' \item \code{Glm} (\code{rms})
#' \item \code{glmer} (\code{lme4})
#' \item \code{glmrob} (\code{robustbase})
#' \item \code{gls} (\code{nlme})
#' \item \code{Gls} (\code{rms})
#' \item \code{gmm} (\code{gmm})
#' \item \code{heckit} (\code{sampleSelection})
#' \item \code{hetglm} (\code{glmx})
#' \item \code{hurdle} (\code{pscl})
#' \item \code{ivreg} (\code{AER})
#' \item \code{lagarlm} (\code{spdep})
#' \item \code{lm} (\code{stats})
#' \item \code{lme} (\code{nlme})
#' \item \code{lmer} (\code{lme4})
#' \item \code{lmrob} (\code{robustbase})
#' \item \code{lrm} (\code{rms})
#' \item \code{maBina} (\code{erer})
#' \item \code{mclogit} (\code{mclogit})
#' \item \code{mlogit} (\code{mlogit})
#' \item \code{mnlogit} (\code{mnlogit})
#' \item \code{mlreg} (\code{eha})
#' \item \code{multinom} (\code{nnet})
#' \item \code{nlme} (\code{nlme})
#' \item \code{nlmer} (\code{lme4})
#' \item \code{ols} (\code{rms})
#' \item \code{pgmm} (\code{plm})
#' \item \code{phreg} (\code{eha})
#' \item \code{plm} (\code{plm})
#' \item \code{pmg} (\code{plm})
#' \item \code{polr} (\code{MASS})
#' \item \code{psm} (\code{rms})
#' \item \code{rem.dyad} (\code{relevent})
#' \item \code{rlm} (\code{MASS})
#' \item \code{rq} (\code{quantreg})
#' \item \code{Rq} (\code{rms})
#' \item \code{selection} (\code{sampleSelection})
#' \item \code{svyglm} (\code{survey})
#' \item \code{survreg} (\code{survival})
#' \item \code{tobit} (\code{AER})
#' \item \code{weibreg} (\code{eha})
#' \item \code{zeroin} (\code{pscl})
#' \item \code{relogit} (\code{zelig})
#' \item \code{cloglog.net} (\code{zelig})
#' \item \code{gamma.net} (\code{zelig})
#' \item \code{probit.net} (\code{zelig})
#' \item \code{logit.net} (\code{zelig})
#' }
#' @author Tom Wenseleers, Christophe Vanderaa
#' @example examples/table2tex.R
#' @seealso \code{\link{table2office}} ,\code{\link{table2ppt}}, \code{\link{table2doc}},
#' \code{\link[stargazer]{stargazer}}
#' @export
#'
table2tex = function(x = NULL, file = "Rtable", type="TEX", digits = 2, digitspvals = 2,
trim.pval = 1e-16, summary=FALSE, standAlone=TRUE, add.rownames = FALSE,...) {
# Get the data that will be exported
obj=x
if (is.null(obj))
outp = .Last.value else outp = obj # capture previously shown output or use passed object
if (is.null(outp))
stop("no R stats object available to export")
obj=outp
# Match the requested file type
type=toupper(type)
type=match.arg(type,c("TEX","HTML"))
if (type=="HTML") { ext=".html" }
if (type=="TEX") { ext=".tex" }
file = sub("^(.*)[.].*", "\\1", file) # remove extension if given
file = paste0(file, ext) # add extension
# Depending on the class of the data call the formating function
if (length(intersect(class(obj), as.character(gsub("xtable.", "", methods(xtable))))) >= 1) {
obj <- xtable2(x=obj, ndigits = digits, ndigitspvals = digitspvals, trim.pval=trim.pval)
obj <- as.data.frame(obj)
} else if (length(intersect(class(obj), as.character(gsub("tidy.", "", methods(tidy))))) >= 1) {
obj <- tidy2(x=obj, ndigits = digits, ndigitspvals = digitspvals, trim.pval=trim.pval)
obj <- as.data.frame(obj)
}
# Else supported objects that should be supported by stargazer
if ("aov" %in% class(obj)) {obj=as.data.frame(anova(obj));summary=FALSE}
if ("summary.aov" %in% class(obj)) {obj=as.data.frame(obj);summary=FALSE}
# object supported by stargazer?
supported=!grepl("Unrecognized object type",paste(capture.output(stargazer(obj)),collapse=""))
if (!supported) stop(paste0("Object of class ",class(obj)," is not supported by stargazer."))
# preview table in viewer or browser
htmlout = capture.output(stargazer(obj, type="html", summary=summary, rownames = add.rownames, digits = digits,...))
texout = capture.output(stargazer(obj, type="latex", summary=summary, rownames = add.rownames, digits = digits,...))
outp = preview(htmlout)
# export to HTML/Latex
if (standAlone) {
texheader=c("\\documentclass[10pt]{article}","\\begin{document}")
texfooter=c("\\end{document}")
texout=c(texout[1:3],texheader,texout[4:length(texout)],texfooter)
}
if (type=="HTML") { fileConn = file(file)
writeLines(htmlout,file)
close(fileConn) }
if (type=="TEX") { fileConn = file(file)
writeLines(texout,file)
close(fileConn) }
message(paste0("Exported table as ",file))
}
#' @describeIn table2tex
#' Export statistical output to HTML table
#' @export
table2html = function(...) table2tex(type = "HTML", ...)
================================================
FILE: R/utils.R
================================================
#' @importFrom grDevices recordPlot dev.cur hcl dev.list dev.off
#' @importFrom utils browseURL
#' @import xml2
# function to preview HTML in RStudio viewer or web browser
preview = function(x){
htmlFile = tempfile(fileext=".html")
cat(x, file=htmlFile)
viewer = getOption("viewer")
if ((!is.null(viewer)) && is.function(viewer))
viewer(htmlFile)
else
browseURL(htmlFile)
}
# helper function to show p values right aligned with digitspvals sign digits and
# degrees of freedom columns as right aligned integers
xtable2 = function(x, ndigits = 2, ndigitspvals = 2, trim.pval = 1E-16, ...) {
sm = xtable(x)
ncol = ncol(sm)
digs = rep(ndigits, ncol + 1)
disp = rep("f", ncol + 1)
whch = grep("\\QPr(\\E|\\Qp-value\\E|\\Qp value\\E|\\Qpadj\\E|^p$|^padj$|p[.]value", colnames(sm))
if (length(whch) != 0) {
for(j in whch){ # Format the pvalues in scientific format
sm[,j] <- sapply(sm[,j],function(val){
val <- ifelse(val < trim.pval,
paste0("< ", formatC(trim.pval, format = "e", digits = 0)),
formatC(val, format = "e", digits = ndigitspvals))
return(val)
})
}
}
# whch = grep("^Df$|^df$", colnames(sm))
# if (length(whch) != 0){
# digs[whch + 1] = 0
# disp[whch + 1] = "d"
# }
# digs[c(1,which(!sapply(sm,is.numeric))+1)] <- NA
# disp[c(1,which(!sapply(sm,is.numeric))+1)] <- "s"
# for(i in 2:length(digs)){
# if(disp[i]=="f") sm[,i-1] <- round(sm[,i-1], digits = digs[i])
# }
xtable(sm, digits = digs, display = disp,...)
}
tidy2 <- function(x, ndigits = 2, ndigitspvals = 2, trim.pval = T, ...) {
x <- tidy(x)
ncol = ncol(x)
digs = rep(ndigits, ncol)
whch = grep("\\QPr(\\E|\\Qp-value\\E|\\Qp value\\E|\\Qpadj\\E|^p$|^padj$|p[.]value", colnames(x))
if (length(whch) != 0) { digs[whch] = "pval" }
whch = grep("^Df$|^df$", colnames(x))
if (length(whch) != 0){ digs[whch] = 0 }
digs[!sapply(x,is.numeric)] <- NA
for(i in 1:length(digs)){
if(is.numeric(digs[i])) x[,i] <- round(x[,i], digits = digs[i])
if(digs[i]=="pval"){
x[,i] <- sapply(x[,i],function(val){
ifelse(val < 10^-ndigitspvals & trim.pval,
paste0("<", 10^-ndigitspvals),
formatC(val, format = "f", digits = ndigitspvals))
})
}
}
return(x)
}
data.frame2<- function(x, ndigits = 2, ndigitspvals = 2, trim.pval = T,...) {
x <- data.frame(x, check.names = F)
ncol = ncol(x)
digs = rep(ndigits, ncol)
whch = grep("\\QPr(\\E|\\Qp-value\\E|\\Qp value\\E|\\Qpadj\\E|^p$|^padj$", colnames(x))
if (length(whch) != 0) { digs[whch] = "pval" }
whch = grep("^Df$|^df$", colnames(x))
if (length(whch) != 0){ digs[whch] = 0 }
for(i in 1:length(digs)){
if(is.numeric(digs[i])) x[,i-1] <- round(x[,i-1], digits = digs[i])
if(digs[i]=="pval"){
x[,i-1] <- sapply(x[,i-1],function(val){
ifelse(val < 10^-ndigitspvals & trim.pval,
paste0("<", 10^-ndigitspvals),
formatC(val, format = "f", digits = ndigitspvals))
})
}
}
return(x)
}
# function to capture currently active plot
captureplot = function() {
current.device = dev.cur()
nm = names(current.device)[1L]
if(nm == "null device") stop("no device to print from")
if (dev.cur() == 1)
stop("no active graphics device found")
p = invisible(recordPlot())
p
}
# function to clip a value between an allowed range; x can be a single value, a vector or a matrix
clip = function(x, a, b) {(a + (x-a > 0)*(x-a) - (x-b > 0)*(x-b))}
# function that returns default ggplot colours for n groups
gg_color_hue <- function(n,l=65,c=100) {
hues = seq(15, 375, length=n+1)
hcl(h=hues, l=l, c=c)[1:n]
}
# select rows from a dataframe mydata based on a list of selection conditions given
# in a named list "selection"
# e.g.
# mydata=data.frame(group1=c(rep("MALE",6),rep("FEMALE",6)),group2=c(rep("TREATED",3),rep("UNTREATED",3)))
# selection=list(group1="MALE",group2="TREATED")
# selrows(mydata,selection)
# 1 2 3
selrows=function(mydata,selection) {
nms=names(selection)
sel=data.frame(matrix(TRUE,nrow=nrow(mydata),ncol=length(nms)))
for (i in 1:length(nms)) { sel[,i]=(mydata[,nms[[i]]]==selection[nms[[i]]][[1]]) }
which(apply(sel*1,1,prod)==1)
}
# Function to extract the slide size of a presentation from an XML (for PPT)
# This is needed when using officer package
get.slide.size <- function(doc, units="in"){
doc.xml <- doc$presentation$get()
nodes.xml<- xml_children(doc.xml)
ind <- which(grepl(sapply(nodes.xml, as.character), pattern = "sldSz"))
slide.size <- as.numeric(xml_attrs(nodes.xml[[ind]])[1:2])
fac <- ifelse(units == "cm", 360000, 360000 * 2.54 ) # fac = number of pixels per inch or cm
slide.size <- slide.size/fac
names(slide.size) <- c("width", "height")
return(slide.size)
}
# for a given graph width, height, page orientation and type
# returns the best suited template
# TO DO: maybe still add additional parameter "pageaspectr" to support A4, 16:9 or 4:3
besttemplate = function(w,h,margins = c(top=1,right=1,bottom=1,left=1),orient="auto",type="PPT") {
# size of A5 to A1 landscape PPT/DOC templates
landscA=list(c(8.27,5.83),c(11.7,8.27),c(16.5,11.7),c(23.4,16.5),c(33.1,23.4))
if (type=="PPT" ) {
landscA = lapply(landscA,function(x){
return(x-c(margins["left"]+margins["right"],margins["top"]+margins["bottom"]))
})
}
if (type=="DOC") landscA=lapply(landscA,function(x) x-1)[1:3] # allow for 1 inch margins+DOC only supports A5, A4 and A3
sizes=(5:1)[1:length(landscA)]
portrA=lapply(landscA,rev) # size of A5 to A1 landscape PPT/DOC templates
#w=8.9;h=6.7;
if (orient=="auto") orient=ifelse(w>=h,"landscape","portrait")
bestpagesize=suppressWarnings(ifelse( orient=="landscape",
sizes[max( min(which(w<=unlist(lapply(landscA,head,n=1)))),
min(which(h<=unlist(lapply(landscA,tail,n=1)))) )],
sizes[max( min(which(w<=unlist(lapply(portrA,head,n=1)))),
min(which(h<=unlist(lapply(portrA,tail,n=1)))) )] ))
if (is.na(bestpagesize)) bestpagesize=min(sizes)
return(paste0("A",bestpagesize,"_",orient))
}
# Function that shuts down the newly opened devices to match a previous setup
# if dev.old is NULL, all devices are clsed
dev.reset <- function(dev.init = NULL) {
i <- dev.list()[!dev.list() %in% dev.init]
for (ii in i ) dev.off(ii)
return(NULL)
}
================================================
FILE: README.md
================================================
[](https://cran.r-project.org/package=export)
[](https://cran.r-project.org/package=export)
export version 0.3.0
====================
export is an R package to easily export active R graphs and statistical output
in publication quality to Microsoft Office (Word, PowerPoint and Excel), HTML and Latex.
Features
--------
* Save active R graphs or ggplot2, lattice or base R plots in publication
quality to Microsoft Word, Powerpoint, or various other bitmap or
vector formats using a single command with sensible defaults.
* Fully editable Powerpoint vector format output, enabling manual tidy-up of plot layout.
* Save the output of statistical analysis in R as tables in Excel, Word, PowerPoint, Latex or HTML documents.
* Customize formatting of R outputs.
Installation
------------
* The export package works cross-platform on Windows, Ubuntu & Mac. Some Mac distributions though do not have the cairo device installed by default, and this is required by the export package. This problem is solved if Mac users first install XQuartz, which is available for free from https://www.xquartz.org/.
* You can report bugs at http://github.com/tomwenseleers/export/issues.
If you report a bug, try to send a reproducible example and don't forget to send the result of
```r
sessionInfo()
```
### Official CRAN release
**Get the latest official release from CRAN:**
```r
install.packages("export")
```
### Github development version
**Get the latest development version:**
```r
install.packages("officer")
install.packages("rvg")
install.packages("openxlsx")
install.packages("ggplot2")
install.packages("flextable")
install.packages("xtable")
install.packages("rgl")
install.packages("stargazer")
install.packages("tikzDevice")
install.packages("xml2")
install.packages("broom")
install.packages("devtools")
devtools::install_github("tomwenseleers/export")
```
Getting Started
---------------
```r
library(export)
?graph2ppt
?graph2doc
?graph2svg
?graph2png
?table2ppt
?table2tex
?table2excel
?table2doc
?table2html
## export of ggplot2 plot
library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species,
size = Petal.Width, alpha = I(0.7))
# export to Powerpoint
graph2ppt()
graph2ppt(file="ggplot2_plot.pptx", aspectr=1.7)
# add 2nd slide with same graph 9 inches wide and A4 aspect ratio
graph2ppt(file="ggplot2_plot.pptx", width=9, aspectr=sqrt(2), append=TRUE)
# add 3d slide with same graph with fixed width & height
graph2ppt(file="ggplot2_plot.pptx", width=6, height=5, append=TRUE)
# export to Word
graph2doc()
# export to bitmap or vector formats
graph2svg()
graph2png()
graph2tif()
graph2jpg()
## export of aov Anova output
fit=aov(yield ~ block + N * P + K, npk)
x=summary(fit)
# export to Powerpoint
table2ppt(x=x)
table2ppt(x=x,file="table_aov.pptx")
table2ppt(x=x,file="table_aov.pptx",digits=4,append=TRUE)
table2ppt(x=x,file="table_aov.pptx",digits=4,digitspvals=1,
font="Times New Roman",pointsize=16,append=TRUE)
# export to Word
table2doc(x=x)
# export to Excel
table2excel(x=x, file = "table_aov.xlsx",digits=4,digitspvals=1,
sheetName = "Anova_table", add.rownames = TRUE)
# export to Latex
table2tex(x=x)
# export to HTML
table2html(x=x)
```
License
-------
The export package is licensed under the GPLv2.
================================================
FILE: examples/graph2bitmap.R
================================================
# Create a file name
filen <- tempfile(pattern = "ggplot")
# or
# filen <- paste("YOUR_DIR/ggplot")
# Generate graphical output
library(ggplot2)
library(datasets)
x <- qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7))
plot.fun <- function() {
print(qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = 0.7))
}
# There are 3 ways to use graph2bitmap():
### 1. Pass the plot as an object
graph2png(x = x, file = filen, dpi = 400, height = 5, aspectr = 4)
graph2tif(x = x, file = filen, dpi = 400, height = 5, aspectr = 4)
graph2jpg(x = x, file = filen, dpi = 400, height = 5, aspectr = 4)
### 2. Get the plot from current screen device
x
graph2png(file = filen, dpi = 400, height = 5, aspectr = 4)
graph2tif(file = filen, dpi = 400, height = 5, aspectr = 4)
graph2jpg(file = filen, dpi = 400, height = 5, aspectr = 4)
### 3. Pass the plot as a function
graph2png(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
graph2tif(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
graph2jpg(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
================================================
FILE: examples/graph2office.R
================================================
# Create a file name
filen <- tempfile(pattern = "ggplot") # or
# filen <- paste("YOUR_DIR/ggplot")
# Generate graphical output
library(ggplot2)
library(datasets)
x=qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7))
plot.fun = function(){
print(qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7)))
}
# There are 3 ways to use graph2office():
### 1. Pass the plot as an object
graph2ppt(x=x, file=filen)
graph2doc(x=x, file=filen, aspectr=0.5)
### 2. Get the plot from current screen device
if (interactive()) {
x
graph2ppt(file=filen, width=9, aspectr=2, append = TRUE)
graph2doc(file=filen, aspectr=1.7, append =TRUE)
# Note this requires a graphical device
}
### 3. Pass the plot as a function
if (interactive()) {
graph2ppt(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)
graph2doc(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)
# Note this requires a graphical device
}
### Formatting options:
# Disable vectorized image export (export as a bitmap)
graph2ppt(x=x, file=filen, vector.graphic=FALSE, width=9,
aspectr=sqrt(2), append = TRUE)
# Fill the slide with graph
graph2ppt(x=x, file=filen, margins=0, upscale=TRUE, append=TRUE)
# etc...
================================================
FILE: examples/graph2vector.R
================================================
# Create a file name
filen <- tempfile(pattern = "ggplot") # or
# filen <- paste("YOUR_DIR/ggplot")
# Generate graphical output
library(ggplot2)
library(datasets)
x=qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7))
plot.fun <- function(){
print(qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = 0.7))
}
# There are 3 ways to use graph2vector():
### 1. Pass the plot as an object
graph2svg(x=x, file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
graph2pdf(x=x, file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2eps(x=x, file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
### 2. Get the plot from current screen device
if (interactive()) { # Because the example uses screen devices
x
graph2svg(file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2pdf(file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
graph2eps(file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
}
### 3. Pass the plot as a function
if (interactive()) { # Because the example uses screen devices
graph2svg(file=filen, fun = plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2pdf(file=filen, fun=plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2eps(file=filen, fun=plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
}
================================================
FILE: examples/rgl2bitmap.R
================================================
# Create a file name
filen <- tempfile(pattern = "rgl") # or
# filen <- paste("YOUR_DIR/rgl")
# Generate a 3D plot using 'rgl'
x = y = seq(-10, 10, length = 20)
z = outer(x, y, function(x, y) x^2 + y^2)
rgl::persp3d(x, y, z, col = 'lightblue')
# Save the plot as a png
rgl2png(file = filen)
# Note that omitting 'file' will save in current directory
================================================
FILE: examples/table2office.R
================================================
# 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
================================================
FILE: examples/table2spreadsheet.R
================================================
# 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'
x=summary(fit)
# Save ANOVA table as a CSV
### Option 1: pass output as object
table2csv(x=x,file=filen, digits = 1, digitspvals = 3)
### Option 2: get output from console
summary(fit)
table2csv(file=filen, digits = 2, digitspvals = 4)
# Save ANOVA table as an Excel
# Without formatting of the worksheet
x
table2excel(file=filen, sheetName="aov_noformatting",
digits = 1, digitspvals = 3)
# With formatting of the worksheet
table2excel(x=x,file=filen, sheetName="aov_formated",
append = TRUE, add.rownames=TRUE, fontName="Arial",
fontSize = 14, fontColour = rgb(0.15,0.3,0.75),
border=c("top", "bottom"), fgFill = rgb(0.9,0.9,0.9),
halign = "center", valign = "center", textDecoration="italic")
================================================
FILE: examples/table2tex.R
================================================
# 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'
x=summary(fit)
# Export to Latex in standAlone format
if (interactive()) table2tex(x=x,file=filen)
# Export to Latex to paste in tex document
summary(fit) # get output from the console
if (interactive()) table2tex(file=filen, standAlone = FALSE)
# Export to HTML
if (interactive()) table2html(x=x,file=filen) # or
summary(fit) # get output from the console
if (interactive()) table2html(file=filen)
================================================
FILE: man/graph2bitmap.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/graph2bitmap.R
\name{graph2bitmap}
\alias{graph2bitmap}
\alias{graph2png}
\alias{graph2tif}
\alias{graph2jpg}
\title{Save currently active R graph to bitmap format}
\usage{
graph2bitmap(
x = NULL,
file = "Rplot",
fun = NULL,
type = c("PNG", "JPG", "TIF"),
aspectr = NULL,
width = NULL,
height = NULL,
dpi = 300,
scaling = 100,
font = ifelse(Sys.info()["sysname"] == "Windows", "Arial", "Helvetica")[[1]],
bg = "white",
cairo = TRUE,
tiffcompression = c("lzw", "rle", "jpeg", "zip", "lzw+p", "zip+p"),
jpegquality = 99,
...
)
graph2png(...)
graph2tif(...)
graph2jpg(...)
}
\arguments{
\item{x}{given \code{ggplot2} plot or \code{lattice} plot object to export; if
set to \code{NULL} the currently active R graph will be exported; not
supported for base R plots.}
\item{file}{name of output file. Any extension is ignored and added
according to the requested output type. If file already exists it is overwritten.}
\item{fun}{plot passed on as a function used to create it; useful especially
for base R plots.}
\item{type}{desired output type - \code{PNG}, \code{TIF} or \code{JPG} are currently supported.
\code{PNG} is the preferred format, as it is a lossless format, and compresses better
than \code{TIF}.}
\item{aspectr}{desired width to height aspect ratio. If set to \code{NULL}, the
aspect ratio of the graphics device is used. Can also be combined with one
value for either the desired width or height of the graph.}
\item{width}{desired width in inches; can be combined with a desired
aspect ratio aspectr.}
\item{height}{desired height in inches; can be combined with a desired
aspect ratio aspectr.}
\item{dpi}{desired output in dpi; defaults to 600 dpi.}
\item{scaling}{scale width & height by a certain percentage.}
\item{font}{desired font to use for labels in PNG and TIFF output; defaults to
\code{"Arial"} on Windows systems and to \code{"Helvetica"} on other systems.}
\item{bg}{desired background colour, e.g. \code{"white"} or \code{"transparent"}.}
\item{cairo}{logical, specifying whether or not to use \code{Cairographics} for export.}
\item{tiffcompression}{compression to use for \code{TIF} files.}
\item{jpegquality}{quality of \code{JPEG} compression.}
\item{\dots}{any other options are passed on to \code{grDevices}' \code{\link{png}},
\code{\link{tiff}}, or \code{\link{jpeg}} function (according to the supplied \code{type}).}
}
\value{
No return value
}
\description{
Save the currently active R graph or a graph passed as an object or function
to bitmap format with sensible defaults
}
\section{Functions}{
\itemize{
\item \code{graph2png()}: Save currently active R graph to png file
\item \code{graph2tif()}: Save currently active R graph to TIF file
\item \code{graph2jpg()}: Save currently active R graph to JPEG file
}}
\examples{
# Create a file name
filen <- tempfile(pattern = "ggplot")
# or
# filen <- paste("YOUR_DIR/ggplot")
# Generate graphical output
library(ggplot2)
library(datasets)
x <- qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7))
plot.fun <- function() {
print(qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = 0.7))
}
# There are 3 ways to use graph2bitmap():
### 1. Pass the plot as an object
graph2png(x = x, file = filen, dpi = 400, height = 5, aspectr = 4)
graph2tif(x = x, file = filen, dpi = 400, height = 5, aspectr = 4)
graph2jpg(x = x, file = filen, dpi = 400, height = 5, aspectr = 4)
### 2. Get the plot from current screen device
x
graph2png(file = filen, dpi = 400, height = 5, aspectr = 4)
graph2tif(file = filen, dpi = 400, height = 5, aspectr = 4)
graph2jpg(file = filen, dpi = 400, height = 5, aspectr = 4)
### 3. Pass the plot as a function
graph2png(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
graph2tif(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
graph2jpg(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
}
\seealso{
\code{\link{graph2office}}, \code{\link{graph2vector}}, \code{\link{graph2svg}}, \code{\link{graph2pdf}},
\code{\link{graph2eps}}
}
\author{
Tom Wenseleers
}
================================================
FILE: man/graph2office.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/graph2office.R
\name{graph2office}
\alias{graph2office}
\alias{graph2doc}
\alias{graph2ppt}
\title{Save currently active R graph to Microsoft Office / LibreOffice format}
\usage{
graph2office(
x = NULL,
file = "Rplot",
fun = NULL,
type = c("PPT", "DOC"),
append = FALSE,
aspectr = NULL,
width = NULL,
height = NULL,
scaling = 100,
paper = "auto",
orient = ifelse(type[1] == "PPT", "landscape", "auto"),
margins = c(top = 0.5, right = 0.5, bottom = 0.5, left = 0.5),
center = TRUE,
offx = 1,
offy = 1,
upscale = FALSE,
vector.graphic = TRUE,
...
)
graph2ppt(...)
graph2doc(...)
}
\arguments{
\item{x}{given \code{ggplot2} plot or \code{lattice} plot object to export; if
set to \code{NULL} the currently active R graph will be exported; not
supported for base R plots.}
\item{file}{name of output file. Any extension is ignored and added
according to the requested output type.}
\item{fun}{plot passed on as a function used to create it; useful especially
for base R plots.}
\item{type}{desired output type - \code{DOC} for Word document, \code{PPT} for Powerpoint.}
\item{append}{logical value - if \code{TRUE} and \code{type=PPT} it will append the graph
to the given file, where file can also be a given corporate template. If
\code{append=FALSE} any existing file will be overwritten. Currently ignored in
Word export.}
\item{aspectr}{desired width to height aspect ratio. If set to \code{NULL}, the
aspect ratio of the active graphics device is used.}
\item{width}{desired width in inches; can be combined with a desired
aspect ratio aspectr.}
\item{height}{desired height in inches; can be combined with a desired
aspect ratio aspectr.}
\item{scaling}{scale width & height by a certain percentage.}
\item{paper}{desired paper size to use - "A5" to "A1" for Powerpoint export,
or "A5" to "A3" for Word output; default "auto" automatically selects the
paper size that fits your graph. Graphs that are too large to fit on a given
paper size are scaled down.}
\item{orient}{desired paper orientation - "auto", "portrait" or "landscape";
default to "auto" for Word output and to "landscape" for Powerpoint.}
\item{margins}{vector with the desired margins that should be left blank in}
\item{center}{logical specifying whether or not to center the graph
in the exported Powerpoint.}
\item{offx}{if center is set to \code{FALSE}, the desired x offset at which to
place one's graph in Powerpoint output.}
\item{offy}{if center is set to \code{FALSE}, the desired y offset at which to
place one's graph in Powerpoint output.}
\item{upscale}{logical specifying whether or not to upscale one's graph to
make it page-filling (excluding the margins). Note that scaling may result
in a different look of one's graph relative to how it looks on the screen
due to the change in size.}
\item{vector.graphic}{logical specifying whether or not to output in
vectorized format. This avoids pixelated images in the document. Note that
for PowerPoint, the image can be edited after first ungrouping the plot
elements. If set to \code{FALSE}, the plot is rasterized to \code{PNG} bitmap
format at a resolution of 300 dpi.}
\item{\dots}{any other options are passed on to \code{rvg}'s
\code{\link[rvg]{dml_pptx}} function if \code{type == "DOC"} or to
\code{devEMF}'s \code{\link[devEMF]{emf}} function if \code{type == "PPT"} (only
when \code{vector.graphics == TRUE}).}
}
\value{
No return value
}
\description{
Save the currently active R graph or a graph passed as an object or function
to Microsoft Office / LibreOffice format with sensible defaults
}
\section{Functions}{
\itemize{
\item \code{graph2ppt()}: Save currently active R graph to a Microsoft Office PowerPoint/LibreOffice Impress presentation
\item \code{graph2doc()}: Save currently active R graph to a Microsoft Office Word/LibreOffice Writer document
}}
\examples{
# Create a file name
filen <- tempfile(pattern = "ggplot") # or
# filen <- paste("YOUR_DIR/ggplot")
# Generate graphical output
library(ggplot2)
library(datasets)
x=qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7))
plot.fun = function(){
print(qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7)))
}
# There are 3 ways to use graph2office():
### 1. Pass the plot as an object
graph2ppt(x=x, file=filen)
graph2doc(x=x, file=filen, aspectr=0.5)
### 2. Get the plot from current screen device
if (interactive()) {
x
graph2ppt(file=filen, width=9, aspectr=2, append = TRUE)
graph2doc(file=filen, aspectr=1.7, append =TRUE)
# Note this requires a graphical device
}
### 3. Pass the plot as a function
if (interactive()) {
graph2ppt(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)
graph2doc(fun=plot.fun, file=filen, aspectr=0.5, append = TRUE)
# Note this requires a graphical device
}
### Formatting options:
# Disable vectorized image export (export as a bitmap)
graph2ppt(x=x, file=filen, vector.graphic=FALSE, width=9,
aspectr=sqrt(2), append = TRUE)
# Fill the slide with graph
graph2ppt(x=x, file=filen, margins=0, upscale=TRUE, append=TRUE)
# etc...
}
\seealso{
\code{\link{graph2vector}}, \code{\link{graph2svg}}, \code{\link{graph2pdf}}, \code{\link{graph2eps}},
\code{\link{graph2bitmap}}, \code{\link{graph2png}}, \code{\link{graph2tif}}, \code{\link{graph2jpg}}
}
\author{
Tom Wenseleers, Christophe Vanderaa
}
================================================
FILE: man/graph2vector.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/graph2vector.R
\name{graph2vector}
\alias{graph2vector}
\alias{graph2svg}
\alias{graph2pdf}
\alias{graph2eps}
\title{Save currently active R graph to vector format}
\usage{
graph2vector(
x = NULL,
file = "Rplot",
fun = NULL,
type = "SVG",
aspectr = NULL,
width = NULL,
height = NULL,
scaling = 100,
font = ifelse(Sys.info()["sysname"] == "Windows", "Arial", "Helvetica")[[1]],
bg = "white",
colormodel = "rgb",
cairo = TRUE,
fallback_resolution = 600,
...
)
graph2svg(...)
graph2pdf(...)
graph2eps(...)
}
\arguments{
\item{x}{given \code{ggplot2} plot or \code{lattice} plot object to export; if
set to \code{NULL} the currently active R graph will be exported; not
supported for base R plots.}
\item{file}{name of output file. Any extension is ignored and added
according to the requested output type. If file already exists it is overwritten.}
\item{fun}{plot passed on as a function used to create it; useful especially
for base R plots.}
\item{type}{desired output type - \code{SVG}, \code{PDF} or \code{EPS} are currently supported.
\code{SVG} is the preferred format, and good for editing in Inkscape; \code{PDF} is good
for printing; \code{EPS} is sometimes requested by journals, though lower quality,
especially when semi-transparency is used, as this is rasterized to bitmap.
\code{\link{graph2office}} is recommended for vector output to Microsoft Office.}
\item{aspectr}{desired width to height aspect ratio. If set to \code{NULL}, the
aspect ratio of the graphics device is used. Can also be combined with one
value for either the desired width or height of the graph.}
\item{width}{desired width in inches; can be combined with a desired
aspect ratio aspectr.}
\item{height}{desired height in inches; can be combined with a desired
aspect ratio aspectr.}
\item{scaling}{scale width & height by a certain percentage.}
\item{font}{desired font to use for labels; defaults to \code{"Arial"} on Windows
systems and to \code{"Helvetica"} on other systems. Fonts are embedded by default in \code{EPS} output.}
\item{bg}{desired background colour, e.g. \code{"white"} or \code{"transparent"}.}
\item{colormodel}{desired colormodel in \code{pdf} or \code{eps} output when \code{cairo=FALSE};
currently allowed values are \code{"rgb"} (default), \code{"cmyk"}, \code{"srgb"}, \code{"srgb+gray"}, \code{"rgb-nogray"},
and \code{"gray"} (or \code{"grey"}).}
\item{cairo}{logical indicating whether or not to use the \code{cairo} graphics
device for output to \code{PDF} or \code{EPS}, defaults to \code{TRUE}, thereby allowing for
simulated semi-transparency in \code{EPS} output, by rasterizing semi-transparent
sections, and automated font embedding.}
\item{fallback_resolution}{resolution in dpi to use to rasterize non-supported
vector graphics (e.g. semi-transparent vector elements in \code{EPS}) output).}
\item{\dots}{any other options are passed on to \code{\link{svg}}, \code{\link{cairo_pdf}}, \code{\link{cairo_ps}}, \code{\link{pdf}} or
postscript.}
}
\value{
No return value
}
\description{
Save the currently active R graph or a graph passed as an object or function
to vector format with sensible defaults
}
\section{Functions}{
\itemize{
\item \code{graph2svg()}: Save currently active R graph to SVG format
\item \code{graph2pdf()}: Save currently active R graph to PDF format
\item \code{graph2eps()}: Save currently active R graph to EPS format
}}
\examples{
# Create a file name
filen <- tempfile(pattern = "ggplot") # or
# filen <- paste("YOUR_DIR/ggplot")
# Generate graphical output
library(ggplot2)
library(datasets)
x=qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = I(0.7))
plot.fun <- function(){
print(qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Petal.Width, alpha = 0.7))
}
# There are 3 ways to use graph2vector():
### 1. Pass the plot as an object
graph2svg(x=x, file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
graph2pdf(x=x, file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2eps(x=x, file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
### 2. Get the plot from current screen device
if (interactive()) { # Because the example uses screen devices
x
graph2svg(file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2pdf(file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
graph2eps(file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
}
### 3. Pass the plot as a function
if (interactive()) { # Because the example uses screen devices
graph2svg(file=filen, fun = plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2pdf(file=filen, fun=plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2eps(file=filen, fun=plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
}
}
\seealso{
\code{\link{graph2office}}, \code{\link{graph2bitmap}}, \code{\link{graph2png}}, \code{\link{graph2tif}}, \code{\link{graph2jpg}}
}
\author{
Tom Wenseleers
}
================================================
FILE: man/rgl2bitmap.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rgl2bitmap.R
\name{rgl2bitmap}
\alias{rgl2bitmap}
\alias{rgl2png}
\title{Save currently active rgl 3D graph to bitmap format}
\usage{
rgl2bitmap(file = "Rplot", type = c("PNG"))
rgl2png(...)
}
\arguments{
\item{file}{name of output file. Any extension is ignored and added
according to the requested output type. If file already exists it is overwritten.}
\item{type}{desired output type - currently only \code{PNG} is supported.}
\item{\dots}{passing the \code{rgl2png} arguments to \code{rgl2bitmap}}
}
\value{
No return value
}
\description{
Save currently active rgl 3D graph to bitmap format in current orientation
}
\section{Functions}{
\itemize{
\item \code{rgl2png()}: Save currently active rgl 3D graph to PNG format
}}
\examples{
# Create a file name
filen <- tempfile(pattern = "rgl") # or
# filen <- paste("YOUR_DIR/rgl")
# Generate a 3D plot using 'rgl'
x = y = seq(-10, 10, length = 20)
z = outer(x, y, function(x, y) x^2 + y^2)
rgl::persp3d(x, y, z, col = 'lightblue')
# Save the plot as a png
rgl2png(file = filen)
# Note that omitting 'file' will save in current directory
}
\author{
Tom Wenseleers
}
================================================
FILE: man/table2office.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/table2office.R
\name{table2office}
\alias{table2office}
\alias{table2doc}
\alias{table2ppt}
\title{Export statistical output to a table in Microsoft Office / LibreOffice format}
\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(...)
}
\arguments{
\item{x}{given R stats object to export; if set to \code{NULL} the output of the
previous R command will be exported.}
\item{file}{name of output file. The .pptx or .docx extension is added automatically.}
\item{type}{desired output type - \code{"PPT"} for PowerPoint and \code{"DOC"} for Word.}
\item{append}{logical value - if \code{TRUE} and \code{type="PPT"} or \code{"DOC"} it will
append the table to the given file, where file can also be a given corporate. If
\code{append=FALSE} any existing file will be overwritten.}
\item{digits}{number of digits after the comma (for all numeric columns
except p-values or degrees of freedom)}
\item{digitspvals}{number of digits after the comma (for p-values only). The
default is equal to \code{digits}.}
\item{trim.pval}{a threshold below which the p-values are trimmed as
"< \code{trim.pval}".}
\item{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.}
\item{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.}
\item{offx}{x offset in inches to specify horizontal location of table (only for \code{type=="PPT"}).}
\item{offy}{y offset in inches to specify vertical location of table (only for \code{type=="PPT"}).}
\item{font}{desired font to use for output table; defaults to \code{"Arial"} on Windows
systems and to \code{"Helvetica"} on other systems.}
\item{pointsize}{desired font point size.}
\item{add.rownames}{logical specifying whether or not to add row names.}
\item{\dots}{Further arguments to be passed to \code{table2office}.}
}
\value{
\code{\link[flextable]{flextable}} object
}
\description{
Export currently showing R stats object or stats object obj to a Microsoft
Office / LibreOffice table
}
\details{
Columns corresponding to degrees of freedom (with header "Df" or "df")
are always given as integers. Objects that can be exported with \code{\link{table2office}} are
all those supported by \code{\link[xtable]{xtable}} and \code{\link[broom]{tidy}}. The function will
first use \code{\link[xtable]{xtable}} to format the data. If the data class is not supported by
\code{\link[xtable]{xtable}} the function will then use \code{\link[broom]{tidy}}.
The data classes suported by \code{\link[xtable]{xtable}} are:
\itemize{
\item \code{anova}
\item \code{aov}
\item \code{aovlist}
\item \code{data.frame}
\item \code{glm}
\item \code{gmsar}
\item \code{lagImpact}
\item \code{lm}
\item \code{matrix}
\item \code{prcomp}
\item \code{sarlm}
\item \code{sarlm.pred}
\item \code{spautolm}
\item \code{sphet}
\item \code{splm}
\item \code{stsls}
\item \code{summary.aov}
\item \code{summary.aovlist}
\item \code{summary.glm}
\item \code{summary.gmsar}
\item \code{summary.lm}
\item \code{summary.prcomp}
\item \code{summary.sarlm}
\item \code{summary.spautolm}
\item \code{summary.sphet}
\item \code{summary.splm}
\item \code{summary.stsls}
\item \code{table}
\item \code{ts}
\item \code{zoo}
}
The data classes suported by \code{\link[broom]{tidy}} are:
\itemize{
\item \code{aareg}
\item \code{acf}
\item \code{Arima}
\item \code{betareg}
\item \code{biglm}
\item \code{binDesign}
\item \code{binWidth}
\item \code{brmsfit}
\item \code{btergm}
\item \code{cch}
\item \code{character}
\item \code{cld}
\item \code{coeftest}
\item \code{confint.glht}
\item \code{cv.glmnet}
\item \code{default}
\item \code{density}
\item \code{dgCMatrix}
\item \code{dgTMatrix}
\item \code{dist}
\item \code{emmGrid}
\item \code{ergm}
\item \code{felm}
\item \code{fitdistr}
\item \code{ftable}
\item \code{gam}
\item \code{Gam}
\item \code{gamlss}
\item \code{geeglm}
\item \code{glht}
\item \code{glmnet}
\item \code{glmRob}
\item \code{gmm}
\item \code{htest}
\item \code{ivreg}
\item \code{kappa}
\item \code{kde}
\item \code{kmeans}
\item \code{Line}
\item \code{Lines}
\item \code{list}
\item \code{lme}
\item \code{lmodel2}
\item \code{lmRob}
\item \code{logical}
\item \code{lsmobj}
\item \code{manova}
\item \code{map}
\item \code{Mclust}
\item \code{merMod}
\item \code{mle2}
\item \code{muhaz}
\item \code{multinom}
\item \code{nlrq}
\item \code{nls}
\item \code{NULL}
\item \code{numeric}
\item \code{orcutt}
\item \code{pairwise.htest}
\item \code{plm}
\item \code{poLCA}
\item \code{Polygon}
\item \code{Polygons}
\item \code{power.htest}
\item \code{pyears}
\item \code{rcorr}
\item \code{ref.grid}
\item \code{ridgelm}
\item \code{rjags}
\item \code{roc}
\item \code{rowwise_df}
\item \code{rq}
\item \code{rqs}
\item \code{sparseMatrix}
\item \code{SpatialLinesDataFrame}
\item \code{SpatialPolygons}
\item \code{SpatialPolygonsDataFrame}
\item \code{spec}
\item \code{speedlm}
\item \code{stanfit}
\item \code{stanreg}
\item \code{summary.glht}
\item \code{summaryDefault}
\item \code{survdiff}
\item \code{survexp}
\item \code{survfit}
\item \code{survreg}
\item \code{tbl_df}
\item \code{TukeyHSD}
}
}
\section{Functions}{
\itemize{
\item \code{table2ppt()}: Export statistical output to a table in a Microsoft Office PowerPoint/ LibreOffice Impress presentation
\item \code{table2doc()}: Export statistical output to a table in a Microsoft Office Word/ LibreOffice Writer document
}}
\examples{
# 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
}
\seealso{
\code{\link{table2tex}}, \code{\link{table2html}}, \code{\link{table2spreadsheet}}
}
\author{
Tom Wenseleers, Christophe Vanderaa
}
================================================
FILE: man/table2spreadsheet.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/table2spreadsheet.R
\name{table2spreadsheet}
\alias{table2spreadsheet}
\alias{table2excel}
\alias{table2csv}
\alias{table2csv2}
\title{Export statistical output to a table in spreadsheet compatible format (.xlsx or .csv)}
\usage{
table2spreadsheet(
x = NULL,
file = "Rtable",
type = c("XLS", "CSV", "CSV2"),
append = FALSE,
sheetName = "new sheet",
digits = 2,
digitspvals = 2,
trim.pval = 1e-16,
add.rownames = FALSE,
...
)
table2excel(...)
table2csv(...)
table2csv2(...)
}
\arguments{
\item{x}{given R stats object to export; if set to \code{NULL} the output of the
previous R command will be exported.}
\item{file}{name of output file. The .xlsx or .csv extension is added automatically.}
\item{type}{desired output type - \code{"XLS"} for Excel and \code{"CSV"}/\code{"CSV2"} for CSV file. Note that
\code{type="CSV2"} will generate a CSV file where the value separator is a semi-colon (";") and the decimal
separator is a comma (",")}
\item{append}{logical value - if \code{TRUE} and \code{type="XLS"} it will add a new woorksheet to the given
file, where file can also be a given corporate.
\code{append=FALSE} any existing file will be overwritten.}
\item{sheetName}{a string giving the name of the new sheet that is created (only for \code{type=="XLS"}).
It must be unique (case insensitive) from any existing sheet name in the file.}
\item{digits}{number of significant digits to show for all columns except
for the column with p values.}
\item{digitspvals}{number of significant digits to show for columns with p
values.}
\item{trim.pval}{a threshold below which the p-values are trimmed as
"< \code{trim.pval}".}
\item{add.rownames}{logical specifying whether or not to add row names.}
\item{\dots}{extra options are passed on to \code{\link[openxlsx]{createStyle}} for the formatting of the woorksheet.
This is only applicable for \code{type=="XLS"}.}
}
\value{
A data frame
}
\description{
Export currently showing R stats object or stats object obj to a Microsoft Excel /
LibreOffice Calc or comma-separated value file
}
\details{
Columns corresponding to degrees of freedom (with header "Df" or "df")
are always given as integers. Objects that can be exported with \code{\link{table2office}} are
all those supported by \code{\link[xtable]{xtable}} and \code{\link[broom]{tidy}}. The function will
first use \code{\link[xtable]{xtable}} to format the data. If the data class is not supported by
\code{\link[xtable]{xtable}} the function will then use \code{\link[broom]{tidy}}.
The data classes suported by \code{\link[xtable]{xtable}} are:
\itemize{
\item \code{anova}
\item \code{aov}
\item \code{aovlist}
\item \code{data.frame}
\item \code{glm}
\item \code{gmsar}
\item \code{lagImpact}
\item \code{lm}
\item \code{matrix}
\item \code{prcomp}
\item \code{sarlm}
\item \code{sarlm.pred}
\item \code{spautolm}
\item \code{sphet}
\item \code{splm}
\item \code{stsls}
\item \code{summary.aov}
\item \code{summary.aovlist}
\item \code{summary.glm}
\item \code{summary.gmsar}
\item \code{summary.lm}
\item \code{summary.prcomp}
\item \code{summary.sarlm}
\item \code{summary.spautolm}
\item \code{summary.sphet}
\item \code{summary.splm}
\item \code{summary.stsls}
\item \code{table}
\item \code{ts}
\item \code{zoo}
}
The data classes suported by \code{\link[broom]{tidy}} are:
\itemize{
\item \code{aareg}
\item \code{acf}
\item \code{Arima}
\item \code{betareg}
\item \code{biglm}
\item \code{binDesign}
\item \code{binWidth}
\item \code{brmsfit}
\item \code{btergm}
\item \code{cch}
\item \code{character}
\item \code{cld}
\item \code{coeftest}
\item \code{confint.glht}
\item \code{cv.glmnet}
\item \code{default}
\item \code{density}
\item \code{dgCMatrix}
\item \code{dgTMatrix}
\item \code{dist}
\item \code{emmGrid}
\item \code{ergm}
\item \code{felm}
\item \code{fitdistr}
\item \code{ftable}
\item \code{gam}
\item \code{Gam}
\item \code{gamlss}
\item \code{geeglm}
\item \code{glht}
\item \code{glmnet}
\item \code{glmRob}
\item \code{gmm}
\item \code{htest}
\item \code{ivreg}
\item \code{kappa}
\item \code{kde}
\item \code{kmeans}
\item \code{Line}
\item \code{Lines}
\item \code{list}
\item \code{lme}
\item \code{lmodel2}
\item \code{lmRob}
\item \code{logical}
\item \code{lsmobj}
\item \code{manova}
\item \code{map}
\item \code{Mclust}
\item \code{merMod}
\item \code{mle2}
\item \code{muhaz}
\item \code{multinom}
\item \code{nlrq}
\item \code{nls}
\item \code{NULL}
\item \code{numeric}
\item \code{orcutt}
\item \code{pairwise.htest}
\item \code{plm}
\item \code{poLCA}
\item \code{Polygon}
\item \code{Polygons}
\item \code{power.htest}
\item \code{pyears}
\item \code{rcorr}
\item \code{ref.grid}
\item \code{ridgelm}
\item \code{rjags}
\item \code{roc}
\item \code{rowwise_df}
\item \code{rq}
\item \code{rqs}
\item \code{sparseMatrix}
\item \code{SpatialLinesDataFrame}
\item \code{SpatialPolygons}
\item \code{SpatialPolygonsDataFrame}
\item \code{spec}
\item \code{speedlm}
\item \code{stanfit}
\item \code{stanreg}
\item \code{summary.glht}
\item \code{summaryDefault}
\item \code{survdiff}
\item \code{survexp}
\item \code{survfit}
\item \code{survreg}
\item \code{tbl_df}
\item \code{TukeyHSD}
}
}
\section{Functions}{
\itemize{
\item \code{table2excel()}: Export statistical output to a table in a Microsoft Office Excel/ LibreOffice Calc spreadsheet
\item \code{table2csv()}: Export statistical output to a table in a CSV format ("," for value separation and "." for decimal)
\item \code{table2csv2()}: Export statistical output to a table in a CSV format (";" for value separation and "," for decimal)
}}
\examples{
# 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'
x=summary(fit)
# Save ANOVA table as a CSV
### Option 1: pass output as object
table2csv(x=x,file=filen, digits = 1, digitspvals = 3)
### Option 2: get output from console
summary(fit)
table2csv(file=filen, digits = 2, digitspvals = 4)
# Save ANOVA table as an Excel
# Without formatting of the worksheet
x
table2excel(file=filen, sheetName="aov_noformatting",
digits = 1, digitspvals = 3)
# With formatting of the worksheet
table2excel(x=x,file=filen, sheetName="aov_formated",
append = TRUE, add.rownames=TRUE, fontName="Arial",
fontSize = 14, fontColour = rgb(0.15,0.3,0.75),
border=c("top", "bottom"), fgFill = rgb(0.9,0.9,0.9),
halign = "center", valign = "center", textDecoration="italic")
}
\seealso{
\code{\link{table2tex}}, \code{\link{table2html}}, \code{\link{table2office}}
}
\author{
Tom Wenseleers, Christophe Vanderaa
}
================================================
FILE: man/table2tex.Rd
================================================
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/table2tex.R
\name{table2tex}
\alias{table2tex}
\alias{table2html}
\title{Export statistical output to HTML or Latex table}
\usage{
table2tex(
x = NULL,
file = "Rtable",
type = "TEX",
digits = 2,
digitspvals = 2,
trim.pval = 1e-16,
summary = FALSE,
standAlone = TRUE,
add.rownames = FALSE,
...
)
table2html(...)
}
\arguments{
\item{x}{given R stats object or list of stats objects to export; if set to \code{NULL}
the output of the previous R command will be exported.}
\item{file}{name of output file. The appropriate extension is added automatically.}
\item{type}{desired output type - \code{"TEX"} for Latex and \code{"HTML"} for HTML.}
\item{digits}{number of significant digits to show for all columns except
for the column with p values.}
\item{digitspvals}{number of significant digits to show for columns with p
values.}
\item{trim.pval}{a threshold below which the p-values are trimmed as
"< \code{trim.pval}".}
\item{summary}{logical indicating whether or not to summarize data files.}
\item{standAlone}{logical indicating whether exported Latex code should be
standalone compilable, or whether it will be pasted into another document.}
\item{add.rownames}{logical indicating whether the names of the rows should be added
to the table (inserting a column before first column).}
\item{\dots}{extra options are passed on to stargazer.}
}
\value{
No return value
}
\description{
Export currently showing R stats object or stats object obj to a
HTML or Latex table
}
\details{
Objects that can be exported are all those supported by \code{\link[xtable]{xtable}},
\code{\link[broom]{tidy}} (see \code{\link{table2office}} for an extensive list of supported
methods), or \code{\link[stargazer]{stargazer}}. The models supported by
\code{\link[stargazer]{stargazer}} are:
\itemize{
\item \code{aftreg} (\code{eha})
\item \code{anova} (\code{stats})
\item \code{aov} (\code{stats})
\item \code{aovlist} (\code{stats})
\item \code{arima} (\code{stats})
\item \code{betareg} (\code{betareg})
\item \code{binaryChoice} (\code{sampleSelection})
\item \code{bj} (\code{rms})
\item \code{brglm} (\code{brglm})
\item \code{censReg} (\code{censReg})
\item \code{coeftest} (\code{lmtest})
\item \code{coxph} (\code{survival})
\item \code{coxreg} (\code{eha})
\item \code{clm} (\code{ordinal})
\item \code{clogit} (\code{survival})
\item \code{cph} (\code{rms})
\item \code{dynlm} (\code{dynlm})
\item \code{ergm} (\code{ergm})
\item \code{errorsarlm} (\code{spdev})
\item \code{felm} (\code{lfe})
\item \code{gam} (\code{mgcv})
\item \code{garchFit} (\code{fGarch})
\item \code{gee} (\code{gee})
\item \code{glm} (\code{stats})
\item \code{Glm} (\code{rms})
\item \code{glmer} (\code{lme4})
\item \code{glmrob} (\code{robustbase})
\item \code{gls} (\code{nlme})
\item \code{Gls} (\code{rms})
\item \code{gmm} (\code{gmm})
\item \code{heckit} (\code{sampleSelection})
\item \code{hetglm} (\code{glmx})
\item \code{hurdle} (\code{pscl})
\item \code{ivreg} (\code{AER})
\item \code{lagarlm} (\code{spdep})
\item \code{lm} (\code{stats})
\item \code{lme} (\code{nlme})
\item \code{lmer} (\code{lme4})
\item \code{lmrob} (\code{robustbase})
\item \code{lrm} (\code{rms})
\item \code{maBina} (\code{erer})
\item \code{mclogit} (\code{mclogit})
\item \code{mlogit} (\code{mlogit})
\item \code{mnlogit} (\code{mnlogit})
\item \code{mlreg} (\code{eha})
\item \code{multinom} (\code{nnet})
\item \code{nlme} (\code{nlme})
\item \code{nlmer} (\code{lme4})
\item \code{ols} (\code{rms})
\item \code{pgmm} (\code{plm})
\item \code{phreg} (\code{eha})
\item \code{plm} (\code{plm})
\item \code{pmg} (\code{plm})
\item \code{polr} (\code{MASS})
\item \code{psm} (\code{rms})
\item \code{rem.dyad} (\code{relevent})
\item \code{rlm} (\code{MASS})
\item \code{rq} (\code{quantreg})
\item \code{Rq} (\code{rms})
\item \code{selection} (\code{sampleSelection})
\item \code{svyglm} (\code{survey})
\item \code{survreg} (\code{survival})
\item \code{tobit} (\code{AER})
\item \code{weibreg} (\code{eha})
\item \code{zeroin} (\code{pscl})
\item \code{relogit} (\code{zelig})
\item \code{cloglog.net} (\code{zelig})
\item \code{gamma.net} (\code{zelig})
\item \code{probit.net} (\code{zelig})
\item \code{logit.net} (\code{zelig})
}
}
\section{Functions}{
\itemize{
\item \code{table2html()}: Export statistical output to HTML table
}}
\examples{
# 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'
x=summary(fit)
# Export to Latex in standAlone format
if (interactive()) table2tex(x=x,file=filen)
# Export to Latex to paste in tex document
summary(fit) # get output from the console
if (interactive()) table2tex(file=filen, standAlone = FALSE)
# Export to HTML
if (interactive()) table2html(x=x,file=filen) # or
summary(fit) # get output from the console
if (interactive()) table2html(file=filen)
}
\seealso{
\code{\link{table2office}} ,\code{\link{table2ppt}}, \code{\link{table2doc}},
\code{\link[stargazer]{stargazer}}
}
\author{
Tom Wenseleers, Christophe Vanderaa
}
gitextract__yr00ue_/
├── .Rbuildignore
├── .github/
│ ├── .gitignore
│ └── workflows/
│ └── check-standard.yaml
├── .gitignore
├── DESCRIPTION
├── NAMESPACE
├── NEWS.md
├── R/
│ ├── export
│ ├── export.rdb
│ ├── export.rdx
│ ├── graph2bitmap.R
│ ├── graph2office.R
│ ├── graph2vector.R
│ ├── rgl2bitmap.R
│ ├── table2office.R
│ ├── table2spreadsheet.R
│ ├── table2tex.R
│ └── utils.R
├── README.md
├── examples/
│ ├── graph2bitmap.R
│ ├── graph2office.R
│ ├── graph2vector.R
│ ├── rgl2bitmap.R
│ ├── table2office.R
│ ├── table2spreadsheet.R
│ └── table2tex.R
├── inst/
│ └── templates/
│ ├── A1_landscape.pptx
│ ├── A1_portrait.pptx
│ ├── A2_landscape.pptx
│ ├── A2_portrait.pptx
│ ├── A3_landscape.docx
│ ├── A3_landscape.pptx
│ ├── A3_portrait.docx
│ ├── A3_portrait.pptx
│ ├── A4_landscape.docx
│ ├── A4_landscape.pptx
│ ├── A4_portrait.docx
│ ├── A4_portrait.pptx
│ ├── A5_landscape.docx
│ ├── A5_landscape.pptx
│ ├── A5_portrait.docx
│ └── A5_portrait.pptx
└── man/
├── graph2bitmap.Rd
├── graph2office.Rd
├── graph2vector.Rd
├── rgl2bitmap.Rd
├── table2office.Rd
├── table2spreadsheet.Rd
└── table2tex.Rd
Condensed preview — 49 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (125K chars).
[
{
"path": ".Rbuildignore",
"chars": 113,
"preview": "examples\n^\\.Rproj\\.user$\ncran-comments.md\n^revdep$\n^.git$\n^export.Rproj$\n^.*\\.Rproj$\n.Rhistory\n.RData\n^\\.github$\n"
},
{
"path": ".github/.gitignore",
"chars": 7,
"preview": "*.html\n"
},
{
"path": ".github/workflows/check-standard.yaml",
"chars": 1877,
"preview": "# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples\n# Need help debugging build failures? Start at"
},
{
"path": ".gitignore",
"chars": 35,
"preview": ".Rproj.user\n.Rhistory\nexport.Rproj\n"
},
{
"path": "DESCRIPTION",
"chars": 2185,
"preview": "Package: export\nType: Package\nTitle: Streamlined Export of Graphs and Data Tables\nVersion: 0.3.1\nAuthors@R: c(person(\"To"
},
{
"path": "NAMESPACE",
"chars": 1261,
"preview": "# Generated by roxygen2: do not edit by hand\n\nexport(graph2bitmap)\nexport(graph2doc)\nexport(graph2eps)\nexport(graph2jpg)"
},
{
"path": "NEWS.md",
"chars": 1323,
"preview": "# export 0.3\r\n\r\n### New features\r\n\r\n* Fixed NOTE that resulted in some temporary files being left on non-interactive\r\nDe"
},
{
"path": "R/export",
"chars": 1056,
"preview": "# File share/R/nspackloader.R\n# Part of the R package, http://www.R-project.org\n#\n# Copyright (C) 1995-2012 The R Cor"
},
{
"path": "R/graph2bitmap.R",
"chars": 5750,
"preview": "#' Save currently active R graph to bitmap format\n#' \n#' Save the currently active R graph or a graph passed as an objec"
},
{
"path": "R/graph2office.R",
"chars": 9829,
"preview": "#' Save currently active R graph to Microsoft Office / LibreOffice format\n#' \n#' Save the currently active R graph or a "
},
{
"path": "R/graph2vector.R",
"chars": 7612,
"preview": "#' Save currently active R graph to vector format\n#' \n#' Save the currently active R graph or a graph passed as an objec"
},
{
"path": "R/rgl2bitmap.R",
"chars": 1328,
"preview": "#' Save currently active rgl 3D graph to bitmap format\r\n#' \r\n#' Save currently active rgl 3D graph to bitmap format in c"
},
{
"path": "R/table2office.R",
"chars": 11466,
"preview": "#' Export statistical output to a table in Microsoft Office / LibreOffice format\n#' \n#' Export currently showing R stats"
},
{
"path": "R/table2spreadsheet.R",
"chars": 9567,
"preview": "#' Export statistical output to a table in spreadsheet compatible format (.xlsx or .csv)\n#' \n#' Export currently showing"
},
{
"path": "R/table2tex.R",
"chars": 7191,
"preview": "#' Export statistical output to HTML or Latex table\n#' \n#' Export currently showing R stats object or stats object obj t"
},
{
"path": "R/utils.R",
"chars": 6588,
"preview": "#' @importFrom grDevices recordPlot dev.cur hcl dev.list dev.off\n#' @importFrom utils browseURL\n#' @import xml2\n\n# funct"
},
{
"path": "README.md",
"chars": 3567,
"preview": "[](https://cran.r-project.org/package=export)\r\n[ \n# or \n# filen <- paste(\"YOUR_DIR/ggplot\")\n\n# Generate graphi"
},
{
"path": "examples/graph2office.R",
"chars": 1318,
"preview": "# Create a file name\nfilen <- tempfile(pattern = \"ggplot\") # or \n# filen <- paste(\"YOUR_DIR/ggplot\")\n\n# Generate graphic"
},
{
"path": "examples/graph2vector.R",
"chars": 1657,
"preview": "# Create a file name\nfilen <- tempfile(pattern = \"ggplot\") # or \n# filen <- paste(\"YOUR_DIR/ggplot\")\n\n# Generate graphic"
},
{
"path": "examples/rgl2bitmap.R",
"chars": 353,
"preview": "# Create a file name\nfilen <- tempfile(pattern = \"rgl\") # or \n# filen <- paste(\"YOUR_DIR/rgl\")\n\n# Generate a 3D plot usi"
},
{
"path": "examples/table2office.R",
"chars": 907,
"preview": "# Create a file name\nfilen <- tempfile(pattern = \"table_aov\") # or \n# filen <- paste(\"YOUR_DIR/table_aov\")\n\n# Generate A"
},
{
"path": "examples/table2spreadsheet.R",
"chars": 1012,
"preview": "# Create a file name\r\nfilen <- tempfile(pattern = \"table_aov\") # or \r\n# filen <- paste(\"YOUR_DIR/table_aov\")\r\n\r\n# Genera"
},
{
"path": "examples/table2tex.R",
"chars": 621,
"preview": "# Create a file name\nfilen <- tempfile(pattern = \"table_aov\") # or \n# filen <- paste(\"YOUR_DIR/table_aov\")\n\n# Generate A"
},
{
"path": "man/graph2bitmap.Rd",
"chars": 4400,
"preview": "% Generated by roxygen2: do not edit by hand\r\n% Please edit documentation in R/graph2bitmap.R\r\n\\name{graph2bitmap}\r\n\\ali"
},
{
"path": "man/graph2office.Rd",
"chars": 5699,
"preview": "% Generated by roxygen2: do not edit by hand\r\n% Please edit documentation in R/graph2office.R\r\n\\name{graph2office}\r\n\\ali"
},
{
"path": "man/graph2vector.Rd",
"chars": 5484,
"preview": "% Generated by roxygen2: do not edit by hand\r\n% Please edit documentation in R/graph2vector.R\r\n\\name{graph2vector}\r\n\\ali"
},
{
"path": "man/rgl2bitmap.Rd",
"chars": 1203,
"preview": "% Generated by roxygen2: do not edit by hand\n% Please edit documentation in R/rgl2bitmap.R\n\\name{rgl2bitmap}\n\\alias{rgl2"
},
{
"path": "man/table2office.Rd",
"chars": 7689,
"preview": "% Generated by roxygen2: do not edit by hand\r\n% Please edit documentation in R/table2office.R\r\n\\name{table2office}\r\n\\ali"
},
{
"path": "man/table2spreadsheet.Rd",
"chars": 7533,
"preview": "% Generated by roxygen2: do not edit by hand\r\n% Please edit documentation in R/table2spreadsheet.R\r\n\\name{table2spreadsh"
},
{
"path": "man/table2tex.Rd",
"chars": 5396,
"preview": "% Generated by roxygen2: do not edit by hand\r\n% Please edit documentation in R/table2tex.R\r\n\\name{table2tex}\r\n\\alias{tab"
}
]
// ... and 18 more files (download for full content)
About this extraction
This page contains the full source code of the tomwenseleers/export GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 49 files (112.5 KB), approximately 36.6k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.