4

I cannot run a R session from the command line by typing 'R', despite having

C:/Program Files/R

and

C:/Program Files/R/R-3.3.2/bin

in both 'Path' (System) and 'PATH' (User) environment variables (the latter directory is where the actual application is located, I was just trying everything by adding the former).

If I manually change the working directory to C:/Program Files/R/R-3.3.2/bin and type R, a session runs.

Any insight as to why this might be the case? Other programs such as Python 3 run fine, provided the the environment variable is set, why not with R?

This question is part of a larger problem where I am trying to get rpy2 working, but though successfully installed, none of it's basic functions are working, and I thought this maybe to do with a version of R being installed at C:/Users/Anaconda2/R (Because this dir was in Path). The R application installed here would not work when opened, but was the directory returned when I typed R RHOME into cmd - despite the fact this installation is not even functioning, and has apparently only existed since I installed rpy2 a couple of hours ago. I reasoned that rpy2 is trying to use the instance of R installed here rather than my normal one, thus causing the error when I call robjects.r. But this still doesn't explain why I can't run R from cmd. When using R.home(component = "home") from inside a an R session (in RStudio or out of it), it returns my normal, working R directory, at C:/PROGRA~1/R/R-33~1.2. By moving the R file tree installed in Anaconda's directory to a somewhere not in Path, I hoped Windows would find the correct installation via Path - but instead I just get Failed to create process.

My last guess was that Windows didn't like the space in "Program Files", but loads of variables in Path go through the same folder. Any ideas?

I am using:

Windows 10, R 3.3.2, Python 2.17.13

UPDATE, PERHAPS SOLVED:

On Josh O'Brien's recommendation (thanks!), I typed where R into cmd, returning:

C:\Users\charl\Anaconda2\Scripts\R.exe
C:\Program Files\R\R-3.3.2\bin\R.exe

The first path is marginally different from the C:\Users\charl\Anaconda2\R listed in my first post (both are in Path), and leads to a third R.exe. It's outside the R file tree located in Anaconda, unlike my standard R installation, but seems to be dependent on it nonetheless. If I remove this R.exe to another location (not in Path), Typing R in cmd will run R from the desired directory, thus fixing the problem. R.home() from inside that session confirms this.

My only remaining concern then; is whether this installation of R in Anaconda necessary for rpy2 or can I just delete it, fixing the original problem? It may just be my ignorance, but I was not conscious that installing rpy2 (I used the standard Windows installer rather than compiling manually) would install another instance of R - is it necessary for the package or just a default/option I failed to omit?

  • 1
    Have you checked the results (from cmd) of `where R`? What happens if you type "C:\Program Files\R\R-3.3.2\bin\R"? Does the value returned by `SET path` include the directory containing R.exe, giving using backslashes (not the forward slashes you've shown)? – Josh O'Brien Jan 27 '17 at 20:24
  • `where R` returns both directories: `C:\Users\charl\Anaconda2\Scripts\R.exe` `C:\Program Files\R\R-3.3.2\bin\R.exe` `SET Path` returns both paths: `C:\Program Files\R-3.3.2\bin` `C:\Users\charl\Anaconda2\Scripts` where copies of R.exe are located (with backslashes). though only the former begins an R session. – Charlie Mealings Jan 29 '17 at 12:54
  • Potentially solved, see edits^^ – Charlie Mealings Jan 29 '17 at 15:30
  • I haven't used rpy2 so can't help you with the specifics of how it finds the executables it needs, but rather than deleting anything, you might just want to modify your PATH variable slightly, so that `C:\Program Files\R\R-3.3.2\bin\` comes before rather than after `C:\Users\charl\Anaconda2\Scripts\` . Hope that helps. – Josh O'Brien Jan 29 '17 at 16:50

0 Answers0