Add date and time to pdf output file name
I am开发者_开发问答 exporting graph outputs from R to a pdf file.
I would like to add the Sys.time()
and Sys.Date(
) to the outfile name.
For instance I have a statement
pdf("output filename.pdf", 8,10)
I would like to output to look like
output filename 2010-03-25 2pm.pdf
or something similar.
Combine Sys.time()
with some formatting to get what you want:
paste(format(Sys.time(), "%Y-%m-%d %I-%p"), "pdf", sep = ".")
[1] "2011-03-24 03-PM.pdf"
Formatting options can be found in ?strptime
You could try
pdf (file=paste (Sys.time(), ".pdf", sep=""))
plot (rnorm (100))
dev.off()
Break it into two steps for easy implementation on other docs.
st=format(Sys.time(), "%Y-%m-%d_%H:%M")
paste("filename_",st, ".pdf", sep = "")
[1] "filename_2018-06-19_11:20.pdf"
精彩评论