Type: | Package |
Title: | Rendering Word Documents with R Inline Code |
Version: | 0.3.6 |
Author: | Tomas Hovorka |
Maintainer: | Tomas Hovorka <tomashovorka@seznam.cz> |
Description: | Serves for rendering MS Word documents with R inline code and inserting tables and plots. |
License: | GPL-3 |
Encoding: | UTF-8 |
Imports: | dplyr, officer (≥ 0.5.0), flextable, xml2 |
RoxygenNote: | 7.2.3 |
Suggests: | knitr, rmarkdown, ggplot2, testthat |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2023-01-03 10:28:39 UTC; tomas |
Repository: | CRAN |
Date/Publication: | 2023-01-12 22:20:02 UTC |
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 |
style |
see style parameter in |
debug |
Boolean of length one; If |
... |
Parameters to be sent to other methods ( |
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 |
... |
Parameters to be sent to other methods (mainly |
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 |
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 |
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 = ''))