0

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
  • did you search for that error message? http://stackoverflow.com/questions/22255924/error-in-filecon-r-cannot-open-the-connection-from-running-brugsfit – rawr Nov 01 '16 at 14:46
  • Yes, I saw that but it didn't seem to apply to my issue as it was not exactly the same error message and situation. I'm not assigning a file to a variable, I'm just creating a new presentation and the template doesn't even work correctly. I've also set the wd and closed and reopened the console several times, so that wasn't it. – whynotbackwards Nov 01 '16 at 15:16
  • the underlying problem is still the same: either the path is wrong or the file does not exist – rawr Nov 01 '16 at 15:19
  • I'm sure it was, so thank you for pointing me in the right direction. I ended up completely reinstalling all of my R programs (R, Rtools, RStudio), and starting from a blank slate. That seemed to fix the incorrect path/non-existent file issue, so all set! – whynotbackwards Nov 01 '16 at 15:43

2 Answers2

0

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.

0

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.

swolf
  • 1,020
  • 7
  • 20