next up previous contents
Next: LION-XE Up: Optimization Previous: Submitting to the Batch   Contents

Using Batch Mode for Splus and R

When using R or S-plus for large simulations, it is adventageous to use the BATCH submission capabilities rather than opening an interactive session. There are many reasons for doing this, some of which are: Basically, if you are running a computationally intense simulation, run it in batch mode! Submitting a program in batch mode is done at the unix prompt. In R, simply type
pearson:~ > R-1.4.1 CMD BATCH batch.in batch.out
or in S
pearson:~ > splus6 BATCH batch.in batch2.out
where batch.in is a text file with R or S commands. An example batch file is given below.
x.bat <- rnorm(1000)
mean(x.bat)
var(x.bat)
Note that this file will generate 1000 standard normal variables and store this vector in x.bat. The mean and variance of this vector are then computed. Submitting this file to R will produce this outfile (similarly for S-plus):
R : Copyright 2002, The R Development Core Team
Version 1.4.1  (2002-01-30)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type `license()' or `licence()' for distribution details.

R is a collaborative project with many contributors.
Type `contributors()' for more information.

Type `demo()' for some demos, `help()' for on-line help, or
`help.start()' for a HTML browser interface to help.
Type `q()' to quit R.

> invisible(options(echo = TRUE))
> x.bat <- rnorm(1000)
> mean(x.bat)
[1] 0.002813524
> var(x.bat)
[1] 1.034795
> 
> 
> 
> proc.time()
[1] 0.70 0.12 1.92 0.00 0.00
>
It should be mentioned that the S or R object x.bat will be in the current S or R working directory. That is, when you start S or R within the same directory, you will see x.bat if you type ls(). The advantage of running a S-plus or R in batch mode is not made apparent by the example given above. However, as your programs become increasingly complex, batch mode might be the way to go.
next up previous contents
Next: LION-XE Up: Optimization Previous: Submitting to the Batch   Contents
Computer Support Group 2002-10-07