Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rscript: command not found

I'm working with R for a while, and I always worked with Rstudio, I tried just now to run a Rscript command in terminal (I have a mac..) and I got this error-

>Rscript script.R
 -bash: Rscript: command not found

when I tried to open R in the terminal I go the same error-

>R
-bash: R: command not found

I can run R code with the Rstudio and the R application, but I know there is a way to run R throw the terminal. Did I miss something when I installed R on my computer? do I need to add R to my PATH?

thanks in advance!

like image 217
T.G. Avatar asked Jul 19 '16 10:07

T.G.


2 Answers

Steps to run R script through Windows command prompt

  1. Set the PATH variable for Rscript.exein the environment variables. Rscript.exe can be found inside bin folder of R. Set the path for Rscript.exe to use Rscript command in Windows command prompt. To check if Rscript.exe has been set environmentally or not, type Rscript in command prompt. The follwoing message should come.

enter image description here

  1. Go to Command Prompt, set the path where your .R file is there.
  2. Run the following command: Here abcd.R is present under Documents folder. So I set path and then run Rscript abcd.R

enter image description here

like image 134
Sowmya S. Manian Avatar answered Sep 17 '22 17:09

Sowmya S. Manian


For those who stumbled upon this but use a mac, you might find this useful. I recently downloaded and installed R and RStudio through the CRAN site. I didn't do it through homebrew. Since I downloaded this install directly from the site, it DID NOT add the RScript executable to my /usr/local/bin directory.

I have locate on my mac so I did a quick lookup:

locate RScript

And I found it here:

/Library/Frameworks/R.framework/Versions/4.0/Resources/bin/Rscript

What I had to do was create a symbolic link to my /usr/local/bin directory to get it to work:

cd /usr/local/bin
ln -s /Library/Frameworks/R.framework/Versions/4.0/Resources/bin/Rscript Rscript

Now I'm able to run Rscript through the command line. This may help someone else out there.

like image 20
Paul Carlton Avatar answered Sep 19 '22 17:09

Paul Carlton