| createRmd | R Documentation |
Automatically creates a Rmd file by appending knitr code chunks to an existing rmd.template
createRmd(outputRmdFn, outputListFn, rmdTemplateFn =
system.file("extdata", "rmd.template.Rmd", package = "wfr"),
libs = c("ggplot2"), tabPars=NULL)
outputRmdFn |
(character) The file name of the produced Rmd file, can contain file paths. |
outputListFn |
(character) The file name of the text file containing the table from |
rmdTemplateFn |
(character,
|
libs |
(character, |
tabPars |
(character, NULL) Table parameters passed to |
This function creates a Rmd file by appending knitr code chunks to the existing rmd.template.
The first appended code chunk is for setting up: loading libraries in libs and rmdTable, and reading outputListFn into a data.frame. The following code chunks are one for each row in outputListFn, ordered by rmdInd and filtered by eval in saveOutput. showObj displays of the object (figure or table) in each row. By default, only its top three parameters are included in the code chunk; additional parameters for table display should be specified through tabPars.
Lines containing R markdown section header in their first cell can be inserted into the Excel file pointed by outputListFn. Here is an example where . represents empty space and ... the remaining cells.
oPath rdsFileName oFileName caption rmdInd eval ...
# Method . . . 1 TRUE .
/path tab1.rds tab1.csv table1 2 TRUE ...
When the Excel file contains many lines, adding those section headers make it easier to see the structure of the R markdown file, and the tables and figures at each layer. createRmd writes those section headers directly into the produced R markdown file.
The final Rmd file should be edited, e.g. the isDocx, outputFileName, title, author and optionally wordTemplateFileName for a customized Word template, before knitting.
none
OUTPUTS, rmd.template
library(wfr)
library(ggplot2)
df1=data.frame(A=c("a","a","b3"),
B=c("b1","b2","b3"),
C1=1:3,C2=2:4)
tmpDir = tempdir()
ofn = file.path(tmpDir, "tab.1.csv")
saveOutput(df1, oFileName = ofn, caption="this is a testing table")
ofn = file.path(tmpDir, "fig.1.png")
saveOutput(qplot(1:10,1:10), oFileName=ofn, caption="this is a testing plot")
exFn=file.path(tmpDir, "all.outputs.xlsx")
rmdFn=file.path(tmpDir, "all.outputs.Rmd")
writeExcel(exFn)
createRmd(rmdFn,exFn, tabPars="fontSize=12,theme='plain'")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.