插入日期&进入WMF文件名的时间

时间:2013-07-02 16:09:21

标签: r graph output

创建一些图形,并希望创建的日期/时间在文件名中。我发现this question的答案对该主题非常有帮助,并且

 paste("plotname",Sys.time(),".wmf",sep='')

实际上吐了

[1] "plotname2013-07-02 11:55:04.wmf"

但是

win.metafile(paste("plotname",Sys.time(),".wmf",sep=''))
# win.metafile("test.wmf")
ggplot(data.file, aes(x = group, y = delta)) + geom_boxplot()
dev.off()

给出

Error in win.metafile(paste("plotname", Sys.time(), ".wmf", sep = "")) : unable to start win.metafile:plotname2013-07-02 11:56:23.wmf() device

使用更简单的win.metafile(“test.wmf”)命令。这有什么问题?

2 个答案:

答案 0 :(得分:2)

Windows文件名不能包含以下字符:

< > : " \ / | ? *

请参阅here作为参考,或参考主题previous SO question

答案 1 :(得分:1)

 win.metafile(paste("plotname",format(Sys.time(),"%y%m%d.%M%H"),".wmf",sep=''))

适合我。我认为问题在于文件的格式 - 根据Hong Ooi的回答,Windos不允许在文件名中使用冒号。这给出了年/月/日小时/分钟的时间

有关格式化的详细信息,请查看http://stat.ethz.ch/R-manual/R-patched/library/base/html/strptime.html。您也可以添加不同的内容,例如:

format(Sys.time(),"%y see? %m")