Rscript: command not found

2019-01-27 00:21发布

问题:

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!

回答1:

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.

  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