oreilly.comSafari Books Online.Conferences.


Analyzing Statistics with GNU R
Pages: 1, 2, 3, 4, 5

Saving Your R Work

R provides several options for saving your work. First, when you execute the q() function to quit your session, R asks:

Save workspace image? [y/n/c]:

Enter y to save your current R session state (so that next time you run R in that same directory, your starting status will be identical to that of the current session). Enter n to exit without saving the current session state, or c to continue the current session.

R provides a capability to plot directly to PNG, JPEG, and PDF files through its display setting options. To plot to a file instead of to the R graphics window, execute the png(), jpeg(), or pdf() function prior to any R plotting function. For example:

> png("myImage.png")
> persp(z,theta=0,phi=60,box=FALSE,col="yellow")

You can also invoke R by using scripts. This permits the integration of R into automated data analysis processes. Here's an R script that reads the S&P 500 data file and produces a PNG image of the data:

dv <- read.table("./SP500.txt", header=FALSE)
plot(dv[,2], type="l")

The command line to execute the script (named gspc.scr) is:

R --no-save <gspc.scr > gspc.log

The --no-save flag tells R not to save the script's session. The text output produced by the script is sent to file gspc.log.


R is a powerful, mature, and very well documented GNU open source project. Though the language syntax is a bit unusual, knowing just a few commands lets you quickly generate quite impressive data products.

R's base documentation consists of six manuals, the PDF versions of which comprise 1,700 total pages. The documents are included with the Windows R executable installation download, but they must be downloaded separately for Linux/Unix and MacOS platforms. "An Introduction to R" is the best choice for those who are just starting out. More specialized and detailed references are also available. The R FAQ answers basic introductory questions about R and discusses licensing and usage policy.

To download R, visit The R Project for Statistical Computing ( site. Click on CRAN to access the Comprehensive R Archive Network of mirrored servers. Documentation is available using the Manuals link. Section 5.6 in the R FAQ provides information about contributing to the R project (reporting bugs, coding new extensions, porting additional features from S, and so on).

Related Links

Kevin Farnham is the owner of Lyra Technical Systems, Inc, a small consulting and publishing company.

Return to

Sponsored by: