Skip to content

How to use Sys.time() while writing a csv file name

5 messages · Vincy Pyne, Pascal Oettli, Jeff Newmiller +1 more

#
Hello,

Try something like that:

 > lgd <- format(Sys.time(), "%Y_%m_%d_%H_%M_%S")

Regards,
Pascal


Le 04/07/2012 14:21, Vincy Pyne a ?crit :
#
You forgot to follow the posting guide and tell us what operating system you are using (sessionInfo), but I am going to guess that you are on Windows where the colon (":") is an illegal symbol in filenames. Try formatting the time explicitly in the conversion to character using the format string definitions found in ?strptime in a format that doesn't include colons.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
Vincy Pyne <vincy_pyne at yahoo.ca> wrote:

            
#
Hello,

It seems that there is a problem with ":".
If you only need the date, you can use as.Date(Sys.time()) instead of the
complete form.
If you need the time, you can try the following commands which change the
":" into "-" :

newsystime<-<-format(Sys.time(),"%Y-%m-%d-%H-%M-%S")
write.csv(data.frame(recovery_rates = rr), file =
paste("recovery_rates_at_", newsystime, ".csv", sep = ""), row.names =
FALSE)
 
Have a good day,
Ptit Bleu.

--
View this message in context: http://r.789695.n4.nabble.com/How-to-use-Sys-time-while-writing-a-csv-file-name-tp4635358p4635363.html
Sent from the R help mailing list archive at Nabble.com.