There is an existing function dev.copy2pdf()that does what it says. There is also a function dev.print()that is similar in that it easily copies a file "*.png", but in my opinion is pretty Hanchen.
, pdf() png():
saveToPDF <- function(...) {
d = dev.copy(pdf,...)
dev.off(d)
}
saveToPNG <- function(...) {
d = dev.copy(png,...)
dev.off(d)
}
plot(rnorm(99), col="red")
saveToPDF("my.pdf", height=4,width=7)
saveToPNG("my.png", height=600, width=400)