Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run an executable in R script

Tags:

r

Is there a way to run an executable from R and capture its output?

As an example:

output <- run_exe("my.exe")
like image 680
Austin Salonen Avatar asked Mar 23 '11 19:03

Austin Salonen


People also ask

Can you compile an R script?

In fact, you can take any R script and compile it into a report that includes commentary, source code, and script output. Reports can be compiled to any output format including HTML, PDF, MS Word, and Markdown. The first call to render creates an HTML document, whereas the second creates a PDF document.

How do I run an R file without Rstudio?

Use the Rscript executable that runs at command line (cmd, Powershell, Bash, etc.): Rscript /path/to/my/Rscript. R . No R app launches or opens in background.

How do I run an R script from the command line?

The most convenient way to run R scripts from the command line is to use Rscript, an alternative front-end to run R code. Rscript is capable of executing R code from different command interpreters, such as a bash script on Linux or a Task Scheduler task on Windows.


1 Answers

Yes, look at system() and its options. Hence

R> res <- system("echo 4/3 | bc -l", intern=TRUE)
R> res
[1] "1.33333333333333333333"
R> 

would be one way to divide four by three in case you mistrust the R engine itself.

like image 134
Dirk Eddelbuettel Avatar answered Sep 28 '22 02:09

Dirk Eddelbuettel