[R] question about "system" command

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 26 08:24:54 CET 2006


It is a little easier to use sprintf, as in

system(sprintf("%s input%03d.dat","C:\\Progra~1\\DOSPROGRAM\\RUN.exe", i))

With formatC it is not obvious why digits=2 is needed, but it would be 
more obvious why width=3 would work.


On Wed, 25 Jan 2006, Austin, Matt wrote:

> Something like this.
>
> See ?formatC, ?paste
>
> for (i in 1:100)
> {
>    system(paste("C:\\Progra~1\\DOSPROGRAM\\RUN.exe input",
>                  formatC(i, digits=2, flag='0'),
>                  '.dat',
>                  sep=''))
> }
>
> --Matt
> Statistician
> Amgen, Inc
>
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Taka Matzmoto
> Sent: Wednesday, January 25, 2006 9:31 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] question about "system" command
>
>
> Hi R Users
> I am going to write a very short script for my small pilot simulation study.
> I need to call a DOS program with different input data files in the middle
> of for loop.
> There are 100 input data files (e.g., input001.dat, input002.dat, .... ,
> input100.dat)
>
> for (1 in i :100)
> {
>    system('"C:\\Program Files\\DOSPROGRAM\\RUN.exe" input001.dat')
> }
>
> I like to change the input data file name as for loop runs. How can I do
> that ?
>
> Thanks in advance
>
> TM
>
> ______________________________________________
> R-help at 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
>
> ______________________________________________
> R-help at 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
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list