Skip to content

Invoking shell commands from within R

4 messages · Fredrik Glockner, Friedrich Leisch, Jonathan Myles +1 more

#
In S-Plus, one can invoke a shell command by prepending it with a "!",
e.g.:

    > !ls

Is something similar available in R?  Is it possible to execute shell
commands from within R?

Fredrik
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
FG> In S-Plus, one can invoke a shell command by prepending it with a "!",
FG> e.g.:
FG> Is something similar available in R?  Is it possible to execute shell
FG> commands from within R?

Yes, use the system() command, see help(system)

.f
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
X-Authentication-Warning: stat.math.ethz.ch: majordom set sender to owner-r-help at stat.math.ethz.ch using -f
   From: fredrigl at math.uio.no (Fredrik Glockner)
   Content-Type: text/plain; charset="iso-8859-1"
   Date: 26 Apr 1999 13:46:53 +0200
   User-Agent: Gnus/5.070083 (Pterodactyl Gnus v0.83) Emacs/20.3
   Sender: owner-r-help at stat.math.ethz.ch
   Precedence: bulk

   In S-Plus, one can invoke a shell command by prepending it with a "!",
   e.g.:

       > !ls

   Is something similar available in R?  Is it possible to execute shell
   commands from within R?

   Fredrik
   -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
   r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
   Send "info", "help", or "[un]subscribe"
   (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
   _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

system("ls")

Jonathan
#
On 26 Apr 1999, Fredrik Glockner wrote:

            
The code to support this is present in main.c.  To compile this in,
place the line

	#define SHELL_ESCAPE

at the top of src/main/main.c.

Using "!" in this way is syntactically ugly and it was a general decision
to not make this a standard R feature (but I left the code in because I
"knew" someone would ask ...).

	Ross

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._