I am trying to create an R Presentation in RStudio (File > New File > R Presentation). But when I try to create one with my working directory set to anything other than my default, I receive an error when it tries to preview.
The error displays in the preview panel just beneath the title where the author and date should be, and it says "Error in readLines(if (is.character(input2)) { : cannot open the connection"
. There are also no other slides that can be displayed even though there should be four from the default template.
I've searched all over but I haven't been able to find anyone with this issue. Anyone have an idea what might be causing this?
I'm running:
- Windows 7 Professional
- RStudio v0.99.903
CodePudding user response:
I completely reinstalled all of my R programs (R, Rtools, RStudio), and started from a blank slate. I can now create a presentation in a non-default working directory. As rawr stated, it was probably being caused because of some underlying path issue with the file being created.
CodePudding user response:
I guess, reinstalling is not necessary. I found that the error is most likely related to setting a working directory in .Rprofile or related files via setwd()
.
When I changed the critical line in my .Rprofile to
if(interactive()) setwd(<my preferred working directory>)
it worked.
I think the .Rprofile file influences the R processes needed for creating the presentation in the background, too. If these processes are always set to your standard working directory, they cannot find the relevant files there. That also explains why it works when you put the presentation into your standard working directory.
EDIT: The line above works because interactive()
is FALSE for these background processes I was talking about. So, for those, the setwd()
is not called.