[R] Delete files with system command on Windows 7

William Dunlap wdunlap at tibco.com
Sat Oct 8 20:50:31 CEST 2011


To run a cmd.exe built-in function use 'cmd /c function arg1 ...', as in
   > status <- system("cmd /C echo foo")
   foo
   > status # 0 means all went well
   [1] 0
as opposed to 
   > status <- system("echo foo")
   > status
   [1] 127
You get a little more information about that 127 return value
by adding intern=TRUE
   > status <- system("echo foo", intern=TRUE)
   Error in system("echo foo", intern = TRUE) : 'echo' not found
   > status
  [1] 127
See, e.g., http://ss64.com/nt/cmd.html for other arguments to cmd.exe.

Like Jeff said, unlink() is an OS-independent way to remove files
and directories so system("cmd /C del ...") is not terribly useful.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Jeff Newmiller
> Sent: Saturday, October 08, 2011 11:20 AM
> To: syrvn; r-help at r-project.org
> Subject: Re: [R] Delete files with system command on Windows 7
> 
> DEL is built in to CMD. Use the R "unlink" function.
> ---------------------------------------------------------------------------
> 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.
> 
> syrvn <mentor_ at gmx.net> wrote:
> 
> It's all in the context of calling commands via the system command in R.
> 
> I just found out that you can run system("pdflatex file") and it works fine.
> So R finds the command "pdflatex" but not the "del" command which I can use
> to delete files.
> 
> I am wondering how I have to call this command to be able for R to find it.
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Delete-files-with-system-command-on-
> Windows-7-tp3885478p3885554.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> _____________________________________________
> 
> 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.
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list