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 |
This function takes a list of functions creating plots and insert into Word document on places with corresponding bookmarks.
addPlots( docxIn, docxOut, Plots = list(), width = 6, height = 6, res = 300, style = NULL, debug = F, ... )
addPlots( docxIn, docxOut, Plots = list(), width = 6, height = 6, res = 300, style = NULL, debug = F, ... )
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 ( |
Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA
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)
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)
This function is basically a loop wrapper around body_add_flextable
function.
body_add_flextables(docxIn, docxOut, flextables, debug = F, ...)
body_add_flextables(docxIn, docxOut, flextables, debug = F, ...)
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 |
Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA
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)
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
examplePath()
examplePath()
Returns path to examples folder
examplePath()
examplePath()
body_add_flextables
,renderInlineCode
,addPlots
.Read Word document and apply functions body_add_flextables
,renderInlineCode
,addPlots
.
renderAll( docxIn, docxOut, flextables = NULL, Plots = NULL, height = 6, width = 6, debug = F )
renderAll( docxIn, docxOut, flextables = NULL, Plots = NULL, height = 6, width = 6, debug = F )
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 |
Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA
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)
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.
renderInlineCode(docxIn, docxOut, debug = F)
renderInlineCode(docxIn, docxOut, debug = F)
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 |
Path to the rendered Word file if the operation was successfull OR officer::rdocx object if docxOut is NA
renderInlineCode( paste(examplePath(),'templates/template1.docx',sep = ''), paste(tempdir(),'/result1.docx',sep = ''))
renderInlineCode( paste(examplePath(),'templates/template1.docx',sep = ''), paste(tempdir(),'/result1.docx',sep = ''))