I have a function that is called from a "sourced" script, whenever certain conditions are met. I have this inside it: if(P > 0.9)save( file = today() , myLMSmodel ); This gives me files that look like this: Thu Jan 8 14:04:43 2009 That works fine on my Mac, but it would be much more convenient to have something like this: LMSMOD_Jan_08_09_1404 Does anyone know how I can do this? (You don't have to put in the underscores, if it's too much work.) Thanks, Gregg Allen
Hi, if i understood correctly, you probably want the something like: ## R format(Sys.time(), "LMSMOD_%b_%d_%y_%H%M") (works on windows, don't know about Mac) Hope that helps a little, Tony Breyal On 8 Jan, 23:47, greggal... at gmail.com wrote:> I have a function that is called from a "sourced" script, whenever > certain conditions are met. > > I have this inside it: ?if(P > 0.9)save( file = today() , myLMSmodel ); > > This gives me files that look like this: Thu Jan ?8 14:04:43 2009 > > That works fine on my Mac, but it would be much more convenient to > have something like this: > > LMSMOD_Jan_08_09_1404 > > Does anyone know how I can do this? > > (You don't have to put in the underscores, if it's too much work.) > > Thanks, > > Gregg Allen > > ______________________________________________ > R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Gregg You could either manipulate the character returned by today(), or try using Sys.time() instead. For example, on Windows, paste(strsplit(date(), ' ')[[1]][c(2,3,5,4)], collapse='_') gives Jan_09_2009_13:40:57 which approaches what you want. Alternatively format(Sys.time(), "%b_%d_%y_%H%M") gives Jan_09_09_1342 which only needs LMSMOD pasted to the front which sep='_'. HTH ... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of > greggallen at gmail.com > Sent: Friday, 9 January 2009 12:47 p.m. > To: r-help at r-project.org > Subject: [R] Creating file names. > > I have a function that is called from a "sourced" script, > whenever certain conditions are met. > > I have this inside it: if(P > 0.9)save( file = today() , > myLMSmodel ); > > > This gives me files that look like this: Thu Jan 8 14:04:43 2009 > > That works fine on my Mac, but it would be much more > convenient to have something like this: > > LMSMOD_Jan_08_09_1404 > > > Does anyone know how I can do this? > > (You don't have to put in the underscores, if it's too much work.) > > Thanks, > > > Gregg Allen > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited.
Your easiest starting point is probably file = format(Sys.time()) and then look at the online help for the strptime function to learn about formatting options. For example format( Sys.time() , '%m%d%y' ) Use paste() and some formatting of Sys.time() to construct the form you are looking for. -Don At 4:47 PM -0700 1/8/09, greggallen at gmail.com wrote:>I have a function that is called from a "sourced" script, whenever >certain conditions are met. > >I have this inside it: if(P > 0.9)save( file = today() , myLMSmodel ); > > >This gives me files that look like this: Thu Jan 8 14:04:43 2009 > >That works fine on my Mac, but it would be much more convenient to >have something like this: > >LMSMOD_Jan_08_09_1404 > > >Does anyone know how I can do this? > >(You don't have to put in the underscores, if it's too much work.) > >Thanks, > > >Gregg Allen > >______________________________________________ >R-help at r-project.org mailing list >https:// stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http:// www. R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062