Re: [R] Automatic creation of file names

From: jim holtman <jholtman_at_gmail.com>
Date: Fri 23 Sep 2005 - 03:48:31 EST

Actually it is easier to use 'sprintf' in this situation:  > sprintf("file%04d", 1:10)
[1] "file0001" "file0002" "file0003" "file0004" "file0005" "file0006" "file0007" "file0008"
[9] "file0009" "file0010"
>

 On 9/22/05, Ted Harding <Ted.Harding@nessie.mcc.ac.uk> wrote:
>
> On 22-Sep-05 Mike Prager wrote:
> > Walter --
> >
> > P.S. The advantage of using formatC over pasting the digits (1:1000)
> > directly is that when one uses leading zeroes, as in the formatC
> > example
> > shown, the resulting filenames will sort into proper order.
> >
> > ...MHP
> >
> >
> > You can use paste() with something like
> >
> > formatC(number,digits=0,wid=3,flag="0")
> >
> > (where number is your loop index) to generate the filenames.
> >
> >
> > on 9/22/2005 10:21 AM Leite,Walter said the following:
> >
> >>I have a question about how to save to the hard drive the one thousand
> >>datasets I generated in a simulation.
> >>://www.R-project.org/posting-guide.html<http://project.org/posting-guide.html>
>
> For this precise question, the replies for filename creation, though
> useful, have been slightly off-target. Walter may presumably want the
> ilenames to be in sortable order corresponding to the numerical order
> of creation, i.e. like
>
> file0001 file0002 ... file1000
>
> The precise formatC specification required for this would be
>
> formatC(n,digits=0,wid=4,format="d",flag="0")
>
> so that
>
> formatC(1,digits=0,wid=4,format="d",flag="0")
> # [1] "0001" -> "file0001"
>
> formatC(999,digits=0,wid=4,format="d",flag="0")
> # [1] "0999" -> "file0999"
>
> formatC(1000,digits=0,wid=4,format="d",flag="0")
> # [1] "1000" -> "file1000"
>
> The suggestions with "wid=3" would give
>
> formatC(999,digits=0,wid=3,format="d",flag="0")
> # [1] "999" -> "file999"
> formatC(1000,digits=0,wid=3,format="d",flag="0")
> # [1] "1000" -> "file1000"
>
> which are now in the wrong order (since "file1000" sorts
> alphabetically prior to "file999".
>
> Also, if "format=d" is not specified we get things like
>
> formatC(100,digits=0,wid=3,flag="0")
> # [1] "1e+02" -> "file1e+02"
>
> which, while a valid filename, is on its head for sorting
> (since now the exponent sorts fastest!).
>
> Best wishes to all,
> Ted.
>
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 22-Sep-05 Time: 17:51:36
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

--
Jim Holtman
Cincinnati, OH
+1 513 247 0281

What the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Sep 23 04:14:14 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 17:39:39 EST