[R] It is possible to use a Shell command inside a R script?

Dirk Eddelbuettel edd at debian.org
Fri Aug 24 16:33:39 CEST 2007

On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
> On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
> > Hi,
> > 
> > It is possible to use a shell command inside a R script?
> > 
> > I'm write a R script and I like to put somes shell commands inside to R. 
> > Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
> The details and available functions depend on the platform, but you want 
> to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
> Windows; on Unix-alikes, you probably won't have the latter two.)

Don't forget pipes. 

R's ability to consistently work on connections that may be local
files, remotes files, program output, ... is a true treasure (and
thanks and credits to, I believe, Brian Ripley to make it so).

Eg you can do this 

  OD <- read.table(pipe("links -dump http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'"), header=FALSE, col.names=c("file", "date"))

to get files and dates of files on CRAN.   

As I recall, this also works on that other operating system, provided
you do all the legwork of installing other tools, setting PATHs etc
to provide what works out of the box on the supposedly unfriendlier OS.


Three out of two people have difficulties with fractions.

More information about the R-help mailing list