Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Script: Determine whether the script is run in the GUI or from command line

Is it possible to determine - from within the script - whether the script is running in the R-GUI (specifically R.app on OS X) or whether it has been called from Terminal/command line (i.e. R --vanilla -f script.R)? If so, how is this possible?

I'm asking because I have a script that can run parallelized (using the doMC library), which should not be used from the GUI. Sometimes I need to further process the data calculated in the script, so I'd like to call the script from the GUI on these occasions.

like image 839
Pascal Avatar asked Jan 07 '10 14:01

Pascal


People also ask

Which command runs R scripts from the terminal?

You need the ? Rscript command to run an R script from the terminal.

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

Starting R If R has been installed properly, simply entering R on the command line of a terminal should start the program. In Windows, the program is typically specified as the action performed when clicking on an icon.

Can you run R from command line?

You can run R from the command line.


2 Answers

Perhaps you are looking for interactive()?

like image 92
Aniko Avatar answered Oct 14 '22 19:10

Aniko


In C, you would use the isatty function. If you could find an equivalent function in R (probably in a UNIX or file system library), that should help.

like image 21
eduffy Avatar answered Oct 14 '22 20:10

eduffy