Possible Duplicate:
Generate multiple graphics from within an R function
Very strange thing happening to me: the following code fails to print to pdf device:
outnames <- c("1.pdf", "2.pdf")
for (n in outnames){
pdf(n)
qplot(1:10)
dev.off()
}
won't print anything to pdf, even though a pdf file is generated. However,
pdf(outnames[2])
qplot(1:10)
dev.off()
will work perfectly well. Any idea why? Reproduced in R 2.11.1.