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!
Steps to run R script through Windows command prompt
PATH
variable for Rscript.exe
in 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..R
file is there.abcd.R
is present under Documents
folder. So I set path and then run Rscript abcd.R
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With