showObj: Display an object in knitr code chunk

View source: R/rmd.util.r

showObjR Documentation

Display an object in knitr code chunk

Description

Display an object in knitr code chunk and set the caption with cross reference.

Usage

showObj(oDf,objID=NULL,isDocx=FALSE,...)

Arguments

oDf

(data.frame or matrix) Refers to OUTPUTS, the table containing the information of saved objects.

isDocx

(boolean, FALSE) is the Rmd output word_document2?

objID

(character, NULL) The objID of the object in oDf. If NULL, it is assigned the label of the code chunk. But when running the code chunk alone, e.g. for debugging, the label is not accessible and must be explicitly supplied.

...

parameters passed to rmdTable to define table properties. Unsupplied properties are taken from the corresponding columns on the row identified by objID, if those cells are not NA.

Value

An object identified by objID, can be a ggplot2 or a table (flextable if isDocx T; kable otherwise)

See Also

rmdTable OUTPUTS

Examples

    library(wfr)
    library(ggplot2)
    isDocx=TRUE

    df1=data.frame(A=c("a","a","b3"),
                   B=c("b1","b2","b3"),
                   C1=1:3,C2=2:4)
    colWidth = "2,1,1,1"
    header = "A | A | C | C || A | A | C1 | C2"
    footer = "A|Arkansas$~ref$|1|header
    || C1|Kansas$^ref$|x|header
    || a|Arizona|2|body"

    
        tmpDir = tempdir()
        ofn = file.path(tmpDir, "t1.csv")
        saveOutput(df1,ofn,caption = "1st testing table",header = header,
                   footer = footer, colWidth = colWidth,fontSize = 12 )
        saveOutput(qplot(1:10,1:10),oPath=tmpDir, caption = "1st testing fig")

        ofn = file.path(tmpDir, "all.outputs.csv")
        write.csv(OUTPUTS,ofn)

        oDf=read.csv(ofn,stringsAsFactors = FALSE)
        showObj(oDf,isDocx,objID = "tab1",rowHeaderInd=2)
        showObj(oDf,objID = "fig2")
    

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