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