Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running R from cmd in windows

Tags:

r

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\
like image 885
user124123 Avatar asked Sep 24 '14 15:09

user124123


People also ask

How do I run an R file in Windows command line?

After you add Rscript to the path, in my case by adding the folder C:\Program Files\R\R-4.0. 2\bin\x64 to the path, be sure to open and close CMD for PATH to refresh. Then open a new window of CMD, and type Rscript , and tell me your output.

How do I start R from command line?

Starting R If R has been installed properly, simply entering R on the command line of a terminal should start the program. In Windows, the program is typically specified as the action performed when clicking on an icon. You can also use this method on a *NIX system that has a window manager such as KDE.

How do I run an Rscript line by line?

To execute one specific line: we simply click into the line we would like to execute and press the button with the green arrow ("execute current line or selection; or CTRL+ENTER ). RStudio will copy this line into the R console and execute the line (as if we would enter the command and press enter).


1 Answers

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.

like image 131
David Gohel Avatar answered Sep 23 '22 03:09

David Gohel