Package 'WordR'

Title: Rendering Word Documents with R Inline Code
Description: Serves for rendering MS Word documents with R inline code and inserting tables and plots.
Authors: Tomas Hovorka
Maintainer: Tomas Hovorka <[email protected]>
License: GPL-3
Version: 0.3.6
Built: 2024-11-16 04:20:24 UTC
Source: https://github.com/cran/WordR

Help Index


Read Word document with bookmarks and create other Word document with rendered plots in place.

Description

This function takes a list of functions creating plots and insert into Word document on places with corresponding bookmarks.

Usage

addPlots(
  docxIn,
  docxOut,
  Plots = list(),
  width = 6,
  height = 6,
  res = 300,
  style = NULL,
  debug = F,
  ...
)

Arguments

docxIn

String of length one; path to Word file with bookmarks OR officer::rdocx object

docxOut

String of length one; path for output Word file or NA

Plots

Named list of functions (or plots - for plots which are stored as objects e.g., ggplot) creating plots to be inserted into the Word file

width

width of the plots in output in inches, either of length 1 (and will be recycled), or same length as Plots

height

height of the plots in output in inches, either of length 1 (and will be recycled), or same length as Plots

res

see res parameter in png

style

see style parameter in body_add_img

debug

Boolean of length one; If True then browser() is called at the beginning of the function

...

Parameters to be sent to other methods (png)

Value

Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA

Examples

library(ggplot2)
Plots<-list(plot1=function()plot(hp~wt,data=mtcars,col=cyl),
 plot2=function()print(ggplot(mtcars,aes(x=wt,y=hp,col=as.factor(cyl)))+geom_point()))
addPlots(
 paste(examplePath(),'templates/templatePlots.docx',sep = ''),
 paste(tempdir(),'/resultPlots.docx',sep = ''),
 Plots,height=4)

Read Word document with bookmarks and create other Word document with rendered tables in place.

Description

This function is basically a loop wrapper around body_add_flextable function.

Usage

body_add_flextables(docxIn, docxOut, flextables, debug = F, ...)

Arguments

docxIn

String of length one; path to Word file with bookmarks OR officer::rdocx object

docxOut

String of length one; path for output Word file or NA

flextables

Named list of flextables; Tables to be inserted into the Word file

debug

Boolean of length one; If True then browser() is called at the beginning of the function

...

Parameters to be sent to other methods (mainly body_add_flextable)

Value

Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA

Examples

library(flextable)
ft_mtcars <- flextable(mtcars)
ft_iris <- flextable(iris)
FT <- list(ft_mtcars=ft_mtcars,ft_iris=ft_iris)
body_add_flextables(
   paste(examplePath(),'templates/templateFT.docx',sep = ''),
   paste(tempdir(),'/resultFT.docx',sep = ''),
   FT)

Returns path to examples folder

Description

Returns path to examples folder

Usage

examplePath()

Value

Returns path to examples folder

Examples

examplePath()

Read Word document and apply functions body_add_flextables,renderInlineCode,addPlots.

Description

Read Word document and apply functions body_add_flextables,renderInlineCode,addPlots.

Usage

renderAll(
  docxIn,
  docxOut,
  flextables = NULL,
  Plots = NULL,
  height = 6,
  width = 6,
  debug = F
)

Arguments

docxIn

String of length one; path to Word file with bookmarks OR officer::rdocx object

docxOut

String of length one; path for output Word file or NA

flextables

Named list of flextables; Tables to be inserted into the Word file

Plots

Named list of functions (or plots - for plots which are stored as objects e.g., ggplot) creating plots to be inserted into the Word file

height

height of the plots in output in inches, either of length 1 (and will be recycled), or same length as Plots

width

width of the plots in output in inches, either of length 1 (and will be recycled), or same length as Plots

debug

Boolean of length one; If True then browser() is called at the beginning of the function

Value

Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA

Examples

library(flextable)
library(ggplot2)
ft_mtcars <- flextable(mtcars)
FT <- list(mtcars=ft_mtcars)
Plots <- list(mtcars1 = ggplot(mtcars, aes(x = wt, y = hp, col = as.factor(cyl))) + geom_point())
renderAll(docxIn=paste0(examplePath(), "templates/templateAll.docx"),
          docxOut=paste0(tempdir(), "/resultsAll.docx"),
          flextables=FT,
          Plots=Plots)

Read Word document with R code blocks, evaluate them and writes the result into another Word document.

Description

Read Word document with R code blocks, evaluate them and writes the result into another Word document.

Usage

renderInlineCode(docxIn, docxOut, debug = F)

Arguments

docxIn

String of length one; path to Word file with bookmarks OR officer::rdocx object

docxOut

String of length one; path for output Word file or NA

debug

Boolean of length one; If True then browser() is called at the beginning of the function

Value

Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA

Examples

renderInlineCode(
  paste(examplePath(),'templates/template1.docx',sep = ''),
  paste(tempdir(),'/result1.docx',sep = ''))