0

Creating some graphs, and want the date/time of creation to be in the filename. I found the answers to this question very helpful on that topic, and

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

does in fact spit out

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

but

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

gives

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

where it works with the simpler win.metafile("test.wmf") command. What's the problem here?

Community
  • 1
  • 1
Krysta
  • 220
  • 3
  • 11
  • 1
    Have you tried reformatting `Sys.time` with `format` like they did in the second answer to the question you referenced? For example: `format(Sys.time(),"%y%m%d")` – dayne Jul 02 '13 at 16:14
  • That works, thanks. Any idea why? – Krysta Jul 02 '13 at 16:18
  • Refer to Hong Ooi's answer with characters not allowed in Windows file names. – dayne Jul 02 '13 at 16:33

2 Answers2

2

Windows file names can't contain the following characters:

< > : " \ / | ? *

See here for the reference, or a previous SO question on the topic.

Community
  • 1
  • 1
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
1
 win.metafile(paste("plotname",format(Sys.time(),"%y%m%d.%M%H"),".wmf",sep=''))

Works for me. I think the problem was with the format of the file - as per Hong Ooi's answer Windos does not allow colons in file names. This gives the time as the year/month/day.hour/minute

Check out http://stat.ethz.ch/R-manual/R-patched/library/base/html/strptime.html for more information on formatting. You can add different things too, like:

format(Sys.time(),"%y see? %m")
dayne
  • 7,504
  • 6
  • 38
  • 56