ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Analyzing Statistics with GNU R
Subject:   dev.off()
Date:   2005-11-26 09:19:40
From:   kfarnham

A member of the R mailing list suggests using the dev.off() statement when writing R graphics to a file (see the "Saving Your R Work" section). The dev.off() statement closes R graphics devices.

While the q() statement does close the output graphics file (because R by default flushes buffers and closes open files as it shuts down), the proper way to close the file is to apply the dev.off() statement.

For example, the script that writes a PNG file of the S&P500 graph should be modified to be:

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