[R] system shell emulation in R

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 24 20:28:25 CEST 2004


On Thu, 24 Jun 2004, Shin, Daehyok wrote:

> Rather than using system() to execute a shell command,
> is there a way to emulate the system shell itself in R?
> For instance, if the function is shell, 
> 
> > getwd()
> [1] "/home/a/b"
> > shell()          # From R to system shell
> $cd ..              # cd command in system shell
> $CTRL+D	       # Return to R
> > getwd()
> [1] "/home/a"

system("/bin/sh") does this for you under a Unix-alike.  But as spawning a 
shell as cd-ing in the child does not change the working directory of the 
parent, the emulation would be imperfect if this worked in R.

Do try it in your favourite shell!

-- 
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