Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many open devices r

Tags:

r

I'm trying to write many graphs to one olocation, but instead its writing a bunch of blank pictures:

my code looks like:

titleplot<-NULL
for(i in 1:99){
  titleplot<-colnames(data[i])
  mypath <- file.path("C:","Users","user.ME","Desktop","graph outputs", paste("myplot_", titleplot, ".jpg", sep = ""))
  plot(data[,i],type="l", main =titleplot)
  jpeg(file=mypath)
  dev.off()
}

Does anyone know why this would happen or how I can remedy this?

like image 897
user124123 Avatar asked Jun 13 '14 14:06

user124123


2 Answers

You are supposed to put your jpeg command before you call your plot command.

jpeg(file=mypath)
plot(...)
dev.off()
like image 151
asb Avatar answered Oct 16 '22 22:10

asb


Combination of the answers from Mohammed Shaker and asb gives this really simple code:

for (i in dev.list()[1]:dev.list()[length(dev.list())]) {
   dev.off()
}

This removes all open graphics devices:

> dev.list()
NULL
like image 7
GMSL Avatar answered Oct 16 '22 22:10

GMSL