Reputation: 7730
The following code works in plain R editor (that comes with R) and does not work in RStudio
pdf('test.pdf')
plot(seq(1:10), seq(1:10))
dev.off()
When I run it in RStudio I get in Acrobat "There was an error opening this document. This file is already open or in use by another application"
I get the same error if I use:
pdf('test.pdf')
to_save<-plot(seq(1:10), seq(1:10))
print(to_save)
dev.off()
I have R version 3.3.3 and RStudio: Version 1.0.136 – © 2009-2016 RStudio, Inc. This is on Win 7.
Any ideas how to troubleshoot?
Upvotes: 0
Views: 204
Reputation: 797
It works fine on my RStudio. In my experience, that message when opening the pdf appears if the connection to the file has not been closed. Do you get the message
null device
1
when executing dev.off()
?
Upvotes: 1
Reputation: 355
If you're ok with ggplot2
, ggsave
is a great option:
ggplot(data.frame(seq(1:10), seq(1:10)),
aes(x = x, y = y)) +
geom_point()
ggsave("test.pdf")
Upvotes: 1