[R] system()

Daniel Nordlund djnordlund at frontier.com
Tue Apr 15 03:26:52 CEST 2014


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Rui Barradas
> Sent: Monday, April 14, 2014 12:09 PM
> To: Doran, Harold; r-help at r-project.org
> Subject: Re: [R] system()
> 
> Hello,
> 
> Try instead
> 
> command <- paste(aa, fnm)
> system(command)
> 
> And read the help page for ?paste
> 
> Hope this helps,
> 
> Rui Barradas
> 
> 
> Em 14-04-2014 20:02, Doran, Harold escreveu:
> > I need to send a system command to another program from within R but
> have a small hangup
> >
> > I'm trying to do something like this
> >
> > system("notepad myfile.txt")
> >
> > But, more generally this is happening to multiple files, so I loop over
> thousands of files. For purposes of an example, my code is something like
> this, which does not work
> >
> > aa <- 'notepad.exe'
> > fnm <- 'myfile.txt'
> > system("aa fnm")
> >
> > Any suggestions?
> > Harold
> >

Harold,

you haven't said what OS you are running under, but given that your example program was notepad.exe I am going to guess some flavor of MS Windows.  The suggestion to use paste() is necessary, but it will probably not be sufficient to solve your problem.  The commands suggested

> command <- paste(aa, fnm)
> system(command)

freezes R on my Win 7 Pro x64 box using either 64-bit R-3.0.3 or R-3.1.0.  You might try switching to shell() instead of system()

> command <- paste(aa, fnm)
> shell(command)

However, it all depends on what programs you are trying to run and what behavior you expect.


Dan

Daniel Nordlund
Bothell, WA USA
 




More information about the R-help mailing list