【问题标题】:Inserting date & time into WMF filename将日期和时间插入 WMF 文件名
【发布时间】:2013-07-02 16:09:20
【问题描述】:

创建一些图表,并希望创建的日期/时间在文件名中。我发现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") 命令一起使用。这里有什么问题?

【问题讨论】:

  • 您是否尝试过将Sys.time 重新格式化为format,就像他们在您引用的问题的第二个答案中所做的那样?例如:format(Sys.time(),"%y%m%d")
  • 这行得通,谢谢。知道为什么吗?
  • 参考 Hong Ooi 的回答,Windows 文件名中不允许使用字符。

标签: r graph output


【解决方案1】:

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

< > : " \ / | ? *

请参阅here 以获取参考,或previous SO question 了解该主题。

【讨论】:

  • (+1) 感谢您的澄清!
【解决方案2】:
 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")

【讨论】:

    猜你喜欢
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    相关资源
    最近更新 更多