createRmd: Create a R markdown file

View source: R/rmd.util.r

createRmdR Documentation

Create a R markdown file

Description

Automatically creates a Rmd file by appending knitr code chunks to an existing rmd.template

Usage

createRmd(outputRmdFn, outputListFn, rmdTemplateFn =
          system.file("extdata", "rmd.template.Rmd", package = "wfr"),
          libs = c("ggplot2"), tabPars=NULL)

Arguments

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 OUTPUTS

rmdTemplateFn

(character, system.file("extdata", "rmd.template.Rmd",package = "wfr")) The file name of the rmd.template

libs

(character, "ggplot2") The names of the libraries needed to execute the object displayed in each knitr code chunk

tabPars

(character, NULL) Table parameters passed to showObj, excluding the 1st three parameters. For example, "fontSize=12, theme='plain'".

Details

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.

Value

none

See Also

OUTPUTS, rmd.template

Examples

    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'")
    

blueskypie/wfr documentation built on Feb. 6, 2024, 4:38 p.m.