9

I'm trying to install rtools, so that I can install another package (Google's causalimpact) and the process has indicated I have a problem with my path environment for R.

Main issue

I can't run R from the cmd window.

The expected behaviour is to output below and give > prompt:

R version 3.1.1 (blah blah)

...

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

However the actual result is:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Additional info

I can however run Rcmd and Rgui (everything apart from R) from cmd without error.

Where R prints output C:\Program Files\R\R-3.1.1\bin\x64\R.exe

Where Rcmd prints output C:\Program Files\R\R-3.1.1\bin\x64\Rcmd.exe

Where Rgui prints output C:\Program Files\R\R-3.1.1\bin\x64\Rgui.exe

Return the same paths pointing to their respective exe files.

This is clearly a problem with my global environment paths, but I cant see why it would produce this error

The paths look like (the R path on the last line) :

     c:\Rtools\bin      
     c:\Rtools\gcc-4.6.3\bin      
     C:\RBuildTools\3.1\bin 
     C:\RBuildTools\3.1\gcc-4.6.3\bin   
     c:\Rtools\bin
     c:\Rtools\gcc-4.6.3\bin  
     C:\Python27\   
     C:\Python34\     
     C:\Python34\Scripts      
     C:\Program Files (x86)\Intel\iCLS Client\   
     C:\Program Files\Intel\iCLS Client\ 
     C:\windows\system32  
     C:\windows 
     C:\windows\System32\Wbem      
     C:\windows\System32\WindowsPowerShell\v1.0\    
     C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86 
     C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64  
     C:\Program Files\Intel\Intel(R) Management Engine Components\DAL    
     C:\Program Files\Intel\Intel(R) Management Engine Components\IPT    
     C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL   
     C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT     
     C:\Program Files (x86)\QuickTime\QTSystem\  
     c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\    
     c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\      
     c:\Program Files\Microsoft SQL Server\100\Tools\Binn\   
     c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\  
     C:\strawberry\c\bin  
     C:\strawberry\perl\site\bin   
     C:\strawberry\perl\bin    
     C:\Program Files\MiKTeX 2.9\miktex\bin\x64\    
     C:\Program Files\MiKTeX 2.9\miktex\bin\x64\
     C:\Program Files\R\R-3.1.1\bin\x64  

I can run Python and Perl from just typing either's name into the cmd window, and as R is pointed to in the same way I can't understand the above error.

If anyone has any suggestions on how I can fix this error I would be very grateful.

I've not asked a question of this nature on here before so any editing / pointers greatly appreciated too.

The raw path:

PATH=C:\Program Files\R\R-3.1.1\bin\x64;C:\Program Files\R\R-3.1.1\bin\x64;c:\Rt
ools\bin;c:\Rtools\gcc-4.6.3\bin;C:\RBuildTools\3.1\bin;C:\RBuildTools\3.1\gcc-4
.6.3\bin;c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;C:\Python27\;C:\Python34\;C:\Pyth
on34\Scripts;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iC
LS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\Sy
stem32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x
86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files\Intel\In
tel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Manageme
nt Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine
 Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Componen
ts\IPT;C:\Program Files (x86)\QuickTime\QTSystem\;c:\Program Files (x86)\Microso
ft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microso
ft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Bi
nn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\strawberry\c\bi
n;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files\MiKTeX 2.9
\miktex\bin\x64\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Users\Tariq.Muma
n\AppData\Local\Pandoc\
JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
user124123
  • 1,642
  • 7
  • 30
  • 50
  • 1
    Have you looked at http://stackoverflow.com/questions/18306362/run-r-script-from-command-line ? Can you explain how your question is different from this issue? – JustinJDavies Sep 29 '14 at 13:33
  • 1
    @JustinJDavies That guy's trying to run a script in cmd, I guess I need to open an interpreter within the cmd window by typing "R" into the cmd, like you can by typing "Python" or "Perl" into the cmd. The other question is also in Linux right? – user124123 Sep 29 '14 at 14:19
  • @JustinJDavies As far as my understanding is, that is how this other package I'm trying to install is running into trouble. – user124123 Sep 29 '14 at 14:22
  • @JustinJDavies Just typing R – user124123 Sep 29 '14 at 14:33
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62121/discussion-between-justinjdavies-and-user1987097). – JustinJDavies Sep 29 '14 at 14:44
  • See also http://stackoverflow.com/questions/10077689/r-cmd-on-windows-7-error-r-is-not-recognized-as-an-internal-or-external-comm?rq=1 – JustinJDavies Sep 29 '14 at 16:51
  • 3
    The error indicates that the space in the "Program Files" directory is getting recognized as a command argument separator. Put quotes around the path. – IRTFM Sep 29 '14 at 17:27
  • I think something else is going on here besides the quoting (otherwise Rcmd wouldn't work). I have also tested an unquoted PATH on a Windows 7 machine (with a space in the path to R), and it works correctly (with and without flags to R). What happens when you type `"C:\Program Files\R\R-3.1.1\bin\x64\R.exe"` (with the quotes)? – nograpes Oct 02 '14 at 19:59
  • @nograpes into PATH or cmd? – user124123 Oct 07 '14 at 08:42

4 Answers4

8

This happen because of the space. CMD understand : execute "C:\Program" with argument "Files\R\R-3.1.1\bin\x64\R.exe".

You should quote the whole string:

"C:\Program Files\R\R-3.1.1\bin\x64\R.exe"

... A trick is to drag and drop the exec file in your command windows from your Windows explorer, your will get the correct string to use.

David Gohel
  • 9,180
  • 2
  • 16
  • 34
7

Try adjusting your PATH variable to PATH=C:\Progra~1\R\R-3.1.1\bin\x64;...

It seems very likely that somehow your system is parsing the whitespace in Program Files as a terminating character in the path. Adjusting the definition as above should make this impossible.

JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
1

Depending on how you are setting your PATH variable you might be running into the 1024 character limit. I tried cutting it down and managed to get it down to 1152 characters removing long folder names and trailing \ characters. You might want to consider cleaning this up and either removing unused paths or using some aliases to group paths of the declaration.

One direct approach would be to edit HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and edit the PATH value directly (then reboot to activate the new value).

Note however that while you can enter a very long path, (up to the maximum environment variable length; 2,048 or 32,768 bytes depending on the source), not all software will be able to read and handle it correctly if it is too long.

JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
1

It's really simple. Just like how you set JDK Path variable for Java , you set R path as :

Path="C:\Program Files\R\R-3.4.2\bin\"

in the Edit System Environment variables in Control Panel.
Check if it works!

Akshaya Natarajan
  • 1,865
  • 15
  • 17