2013-07-02 38 views
0

创建一些图,并希望创建的日期/时间位于文件名中。我找到了答案this question关于该主题非常有帮助,在WMF文件名中插入日期和时间

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 

地方适用于SIM卡pler win.metafile(“test.wmf”)命令。这里有什么问题?

+1

你有没有试过用'format'重新格式化'Sys.time',就像他们在你引用的问题的第二个答案中一样?例如:'format(Sys.time(),“%y%m%d”)' – dayne

+0

这很有效,谢谢。任何想法为什么? – Krysta

+0

请参阅Hong Ooi的回答,不允许在Windows文件名中使用字符。 – dayne

回答

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") 
2

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

< > : " \/| ? * 

here为基准,或者就这个话题previous SO question

+0

(+1)谢谢澄清! – dayne