Add date and time to pdf output file name

2020-05-21 05:31发布

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.

标签: pdf r
3条回答
走好不送
2楼-- · 2020-05-21 05:59

You could try

pdf (file=paste (Sys.time(), ".pdf", sep=""))
plot (rnorm (100))
dev.off()
查看更多
【Aperson】
3楼-- · 2020-05-21 06:13

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"
查看更多
▲ chillily
4楼-- · 2020-05-21 06:19

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

查看更多
登录 后发表回答