0

I have just started to use Sublime Text 2 to edit/write R codes and have installed the SublimeREPL package to execute R code within the editor. When I write a new R script it fails to read files in the SAME directory with the error:

Error in file(file, “rt”) : cannot open the connection

I checked getwd() and it shows C:/windows/system32 which is probably the directory where sublime text is installed.

Is there a way to set the current working directory to the location of the current file. This can be easily done in RStudio with Session > setwd > source file location.

I can use the full path of the data file as a workaround, but I think that is not a convenient solution.

Any help would be greatly appreciated.

AGS
  • 14,288
  • 5
  • 52
  • 67
user2758050
  • 47
  • 1
  • 6

1 Answers1

0

I would check again whether the settings of SUBLIMERepl are configured correctly :

Open Preferences > Package Settings > SublimeREPL > Settings - Default 

copy all the text

then open Preferences > Package Settings > SublimeREPL > Settings - User

overwrite and paste the text there

Restart Sublime

When I then open tools > SublimeREPL > R, I can setwd() as usual. The default getwd() returned "/" for me.

AGS
  • 14,288
  • 5
  • 52
  • 67
TinaW
  • 989
  • 1
  • 18
  • 28
  • Thanks. I did this and now when I open SublimeREPL > R and do getwd() it gives me the working directory of the last .R script that was highlighted before opening SublimeREPL. However, if I now highlight code from a different .R script, SublimeREPL still gives me the old working directory. Is it possible to have a setting in SublimeREPL that changes the getwd() to the current active code's location and not the location that was current when SublimeREPL > R was invoked? – user2758050 Apr 20 '15 at 18:38
  • I don't think so. Highlighting is not execution. You will have to use setwd(). You can consider switching back to RStudio, where Ctrl+Shift+H is the shortcut for changing working directory. By the way, consider accepting the answer above, if it helped. – TinaW Apr 21 '15 at 19:47