If you use {ggplot2} you can either ggsave("your_fullpath_filename") for the last plotted ggplot or
# specify device when saving to a file with unknown extension
# (for example a server supplied temporary file)
file <- tempfile()
ggsave(file, device = "pdf")
unlink(file)