0

I am new to learning R and working in command line. I am attempting to run an R script from command line, however I am getting an error line.

bash: Rscript: command not found

I have searched for a couple hours, tried uninstalling & re-installing R, tried adding Rscript.exe to Path in 'system environment variables'...

When I run echo $PATH I can confirm that the path is listed: C:/Program Files/R/R-4.3.0/bin/Rscript.exe

I am working from the same directory as the R script I am attempting to run.

For reference, I am running Windows 11, R 4.3.0, and using Git Bash.

I have found some similar questions on here, but none of the answers are working for me. I also am at a low level of knowledge on this topic and struggling to follow some suggestions.

Anyhow, if anyone is able to help me out I would super appreciate it! Happy to answer any questions with more details, I just don't know what I need to include.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    You may need to try [`Rscript.exe`](https://stackoverflow.com/a/10764080/1968) (instead of just `Rscript`); be sure to also update the `PATH` environment variable as required: https://stackoverflow.com/q/45629314/1968 – Konrad Rudolph May 24 '23 at 19:49
  • I had not understood how to update the PATH environment variable before, but that link helped - thanks! I successfully updated it (verified by `$ echo $PATH`). I then tried executing both `$ Rscript script_file.R` and `$ Rscript.exe script_file.R`, but I am still getting the same error. – Rachelle Nelson May 24 '23 at 21:49

1 Answers1

1

Your $PATH variable should contain the directory, not the executable. Assuming the command is at C:/Program Files/R/R-4.3.0/bin/Rscript.exe, then echo $PATH needs to show C:/Program Files/R/R-4.3.0/bin.

BigFinger
  • 1,033
  • 6
  • 7
  • Thanks for your answer. In a new session, here is what happened: `echo $PATH` showed `:/home/mydirectory/4-4.3.0/bin/`. I did `export PATH="C:/Program Files/R/R-4.3.0/bin:"$PATH`, repeated `echo $PATH`, and it showed `C:/Program Files/R/R-4.3.0/bin::/home/mydirectory/4-4.3.0/bin/`. Then I tried to run `Rscript script_file.R` and `Rscript.exe script_file.R`, but neither one is working still. – Rachelle Nelson May 25 '23 at 16:47
  • One hypothesis is that the way the path has to be specified in git bash for Windows is not "C:/...". You could try "/c/Program..." instead. The other thing to watch out is the space in "Program Files". To prevent the shell from interpreting the space as a separator you can quote the path (which you already did) or you can escape the space character, i.e. Program\ Files . – BigFinger May 25 '23 at 20:24
  • It works! Thank you so much for your help! What finally worked was `"/c/Program..."`. – Rachelle Nelson May 26 '23 at 17:01