Reputation: 83
I am new to R programming and I am trying to learn it. So, please bear with me if this question is silly!
I am trying to execute the below code in RStudio and I get the following error:
R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
[Workspace loaded from ~/.RData]
> x=rnorm(100)
> y=rnorm(100)
> pdf("Figure.pdf")
**Error in pdf("Figure.pdf") : cannot open file 'Figure.pdf'**
> plot(x,y, col="green")
> dev.off()
null device
I am unable to save or open the pdf file. I tried t o check my permissions and I also ran the Rstudio with administer rights but no luck!
Upvotes: 0
Views: 2787
Reputation: 10875
One can direct the output of R graphics functions to PDF files through the use of the pdf()
function.
The file =
argument is a named argument (versus a positional argument), and therefore one needs to use the name in order to change its value. The reasoning for this is that the PDF device function's default value for file =
allows multiple PDFs to be written, per the R documentation for pdf().
x=rnorm(100)
y=rnorm(100)
pdf(file = "Figure.pdf")
plot(x,y, col="green")
dev.off()
...produces a PDF in the current R working directory that contains the following image.
Upvotes: 2