saveOutput | R Documentation |
Save the current R image or the object rds file and optionally other formats of the object (e.g. csv for tables and png for figures), its caption, and other information related to its appearance in the R markdown file, to the matrix OUTPUTS
saveOutput(obj=NULL,oFileName, saveWorkspace=FALSE, oPath=getwd(), caption=NA ,
rmdInd=NA, eval=TRUE,objID=NA, header=NA, footer=NA,
rowHeaderInd=NA, colWidths=NA, fontSize=11, nRowScroll = 20,
nRowDisplay = 200, maxTableWidth = 7.2, theme = "zebra",
numberOutputFiles=TRUE,...)
ofcmm(num=1)
obj |
The target object, usually a data.frame or ggplot object. If |
oFileName |
(character). The file name of the text (e.g. csv) or image (e.g. png) file of the |
saveWorkspace |
(boolean, FALSE)
|
oPath |
(character, getwd()). The output path. |
caption |
(character, NA). The caption of the target object. |
rmdInd |
(integer, |
eval |
(boolean, TRUE). Should the |
objID |
(character, NA, or |
header |
(character, NA). The header of the |
footer |
(character, NA). The footer of the |
colWidths |
(character, NA). The column width of the |
rowHeaderInd, fontSize, nRowScroll, nRowDisplay, maxTableWidth, theme |
Parameters for |
numberOutputFiles |
(boolean, TRUE). Should the output files be numbered? |
... |
parameters passed to |
num |
the number to deduct from |
For the simplicity of coding, two global variables are created for this function:
OFCOUNTER (integer,1). A global variable to count the number of outputs, initial value is 1.
OUTPUTS
(character matrix, NULL). A global variable to record the information of the current r image file and obj
. At the 1st run of saveOutput
, it is assigned to be a character matrix of following columns:
rImageName
The name of saved R image or rds file, depending on the flag saveWorkspace
.
all other parameters of saveOutput
except obj
, and values assigned by them.
saveOutput
does the following:
Save the current R image as paste0(sprintf("%03d", OFCOUNTER),'.r.image.rdata')
or the object rds file in the oPath
directory.
If oFileName
is provided, save obj
as paste0(sprintf("%03d", OFCOUNTER),'.',oFileName)
in the oPath
directory, using either utils::write.csv
or ggplot2::ggsave
depending on the data type of obj
Create the matrix OUTPUTS
if it is NULL, and assign the values of all other parameters to corresponding columns in OUTPUTS
Increment OFCOUNTER
by 1
ofcmm
deducts OFCOUNTER
by num
. It can be used to remove the information appended to OUTPUTS
from running saveOutput
.
none
OUTPUTS
, OFCOUNTER
library(wfr)
library(ggplot2)
print(OFCOUNTER)
print(OUTPUTS)
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 wrong caption")
print(OFCOUNTER)
print(OUTPUTS)
ofcmm()
print(OFCOUNTER)
saveOutput(df1, oFileName=ofn, caption="this is the correct caption")
print(OUTPUTS)
print(OFCOUNTER)
print(OUTPUTS)
ofn = file.path(tmpDir, "fig.1.png")
saveOutput(qplot(1:10,1:10), oFileName=ofn, caption="this is a testing plot")
print(OFCOUNTER)
print(OUTPUTS)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.