Batch mode in R: a primer

June 19, 2009
64 Views

Much of the time, R is used interactively: a user (like you or me) sits in front of a computer, and types instructions in the R language at the command line. The instructions are executed, the result is displayed on-screen, and then R waits patiently for the next command. But did you know that R can also be used non-interactively? You can prepare a sequence of commands in advance as a script file and have R execute those commands in batch mode, without ever waiting for human intervention. Batch mode is useful in many situations. Perhaps you have a complex…

Much of the time, R is used interactively: a user (like you or me) sits in front of a computer, and types instructions in the R language at the command line. The instructions are executed, the result is displayed on-screen, and then R waits patiently for the next command.

 

But did you know that R can also be used non-interactively? You can prepare a sequence of commands in advance as a script file and have R execute those commands in batch mode, without ever waiting for human intervention. 

Batch mode is useful in many situations. Perhaps you have a complex simulation or analysis that will run for several hours: create a script and run it in batch mode to keep the R console from cluttering your screen (but be sure to save the output in a file to check for errors). If you want to run the job overnight when your computer isn't being used, you can schedule the batch job to start at midnight using your operating system's scheduling tools. Or it might be a production application: a web-server might kick off an R batch job on demand when a customer submits a request on a web form. By the way, even though batch jobs are non-interactive that isn't to say they have no inputs: you can still use all of R's tools to input data from files, web sites — even running machinery.

If you haven't used batch mode before, it's pretty easy: all you need is a script file and access to your operating system's Command window (Commands on Windows, Terminal on Macs, or a shell window on Linux/Unix). Andrej Kastrin has a nice primer on R's batch mode to get you started.

Andrej Kastrin's Blog: Batch processing with R

Link to original post