Batch Processing vs. Interactive Sessions

October 26, 2011

(This article was first published on » R-project, and kindly contributed to R-bloggers)

We introduced batch processing 3 weeks ago. Many people asked about differences and benefits of batch processing or interactive sessions. Lets start with the definitions:

Batch Processing / Batch Jobs:
Batch processing is the execution of a series of programs or only one task on a computer environment without manual intervention. All data and commands are preselected through scripts or command-line parameters and therefore run to completion without human contact. This is termed as “batch processing” or “batch job” because the input data are collected into batches of files and are processed in batches by the program.
In many cases batch jobs are submitted to a job scheduler and run on the first available compute node(s).

Interactive Session:
Interactive sessions prompt the user for input as data or commands. Typically, in an interactive session there is a software running on a computer environment and accepts input from human. This is the simplest way to work on any system – you simply log on and run whatever commands you need to, whether on the command line or in a graphical environment and you log out when you’ve finished.


  • Interactive session are usually used so that a person can become familiar with the computing environment and test their code before attempting a long production run as a batch job.
  • Short tasks, those which require frequent user interaction and those which are graphically intensive are the type that are best done interactively.
  • Batch jobs are best for longer running processes, parallel processes or for running large numbers of short jobs simultaneously.
  • If something can be left running for a significant amount of time without any interaction then it’s almost certainly a batch job.
  • Running processes as batch jobs also has the benefit of allowing you to log out of the system and to log out of the PC you are connecting from. You will get an email as soon as your batch job is done.
  • Batch processing avoids idling the computing resources with minute-by-minute manual intervention and supervision.
  • Batch processing supports reproducibility.


Much of the time R is used in interactive sessions: a user sits in front of his computer, and types instructions into the command line of the programming language. The instructions are executed, the result is displayed on-screen, and then programming language waits for the next command.

But you can uses R or Python with batch processing, too! The user prepares a sequence of commands in advance as a script file (e.g. input.R) and passes the commands into the programming language without ever waiting for human intervention. For the R language many people prefer this command:

R --vanilla < input.R > result.txt

But there are two commands which are more optimized for batch processing and for example deal correctly with error messages:

R CMD BATCH test.R result.txt

(more details at

Rscript test.R > result.txt

(more details at

And if you want to use your script file in your interactive session you can use the command

source("input.R", echo=TRUE)

in your R console.


If you have not used batch mode ever before you should try it. It will improve your analyses in several steps.

To leave a comment for the author, please follow the link and comment on their blog: » R-project. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Dommino data lab

Quantide: statistical consulting and training



CRC R books series

Six Sigma Online Training

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)