Hi
The problem is with the font information that R loads into memory. R
tries to load each unique font only once per session, but there was a
bug (or two) which meant that each time you create a new PDF (or
PostScript) device, R loaded another copy of the font information into
memory. So in your example below, we end up trying to load 10000 font
structures, where each one is not tiny. Hence eventual slow-down,
crashes and/or low-memory messages. A fix has been made to the
development version of R, so you could try that out. Otherwise, I'm
afraid I can only suggest that you produce the plots in multiple R
sessions (has anyone ever tried to use package 'snow' with Sweave?)
Paul
Jan Wijffels wrote:> Dear HelpeRs,
> I have a script where I save several thousands of graphics. These are
> then used in Latex through Sweave. Unfortunately R crashes while making
> these plots and Windows pops up some message that I run low on virtual
> memory. I tried to save the plots using pdf(), windows() and
> postscript() and also tried to run it with R CMD BATCH myscript.R. But
> after a while R slows down and crashes eventually or stops computing.
> I'm using windows XP with R 2.3.1. I included a script that shows the
> problem if you let it run for a while.
>> R.version
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 3.1
> year 2006
> month 06
> day 01
> svn rev 38247
> language R
> version.string Version 2.3.1 (2006-06-01)
>
>
> draw.rectangle <- function(
> label,
> figurename="figure",
> figurepath=getwd(),
> box.gpar=gpar(fill=rgb(red=51, green=51, blue=204, maxColorValue >
255),
> col=rgb(red=128, green=128, blue=128, maxColorValue >
255),
> lwd=2),
> text.gpar=gpar(col="white", fontface="bold",
fontsize=14, cex=1,
> fontfamily="sans"),
> type="pdf") {
> setwd(figurepath)
> if(type == "win"){
> windows(width=1.4, height=0.5)
> }
> else if(type == "pdf"){
> pdf(file = paste(figurename, ".pdf", sep=''), width
= 1.4, height
> = 0.5, onefile = TRUE, family = "Helvetica", paper =
"special")
> }
> else if(type == "ps"){
> postscript(file = paste(figurename, ".ps", sep=''),
width = 1.4,
> height = 0.5, onefile = TRUE, family = "Helvetica", paper =
"special",
> fonts = "sans")
> }
> boxheight <- unit(1, "npc")
> boxwidth <- unit(1, "npc")
> pushViewport(viewport(x=0.5, y=0.5, width = boxwidth, height >
boxheight))
> grid.roundRect(height=boxheight, width=boxwidth, r=unit(3,
"mm"),
> gp = box.gpar)
> grid.text(label, just = "centre", gp = text.gpar)
> popViewport()
> if(type == "win"){
> tmp <- savePlot(filename = figurename, type = "pdf",
device > dev.cur(), restoreConsole = TRUE)
> }
> tmp <- dev.off()
> }
> require(RGraphics)
> setwd("C:\\")
> for(i in 1:10000){
> draw.rectangle("blablabla", type="win")
> }
>
> Anyone has suggestions on how to solve this?
>
>
> Jan
>
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/