0

Please help. I want to run myRcode.R on command prompt windows 8. Therefore I tried to use Rscrip.exe. I changed the name of my file to Rscript myRcode.R but command prompt showed an error: “Rscript not recognized as an internal or external command, operable program, or batch file."
I added C:\Program Files\R\R-3.3.3\bin\x64 to the environment variables in path. But command prompt showed a new error: “cannot open file “myRcode.R”: no such file or directory. I studied many command in this site about this problem, but I could not to use them after two weeks. I am not a professional user.

adele
  • 13
  • 4
  • Possible duplicate of [running R from windows command prompt](https://stackoverflow.com/questions/5720317/running-r-from-windows-command-prompt) – Bill the Lizard Aug 01 '17 at 14:34
  • You might need to verify that R is in that directory. Try running `C:\"Program Files"\R\R-3.3.3\bin\x64\Rscript.exe` by itself from a command window. You should get a usage message if it's there. – Bill the Lizard Aug 01 '17 at 14:40
  • I do it from a command window :usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]..... 'file' may contain spaces but not shell metacharacters Expressions (one or more '-e ') may be used *instead* of 'file' See also ?Rscript from within R. Is it correct? – adele Aug 01 '17 at 17:22
  • Are you running it from the same directory where you saved your script? `C:\"Program Files"\R\R-3.3.3\bin\x64\Rscript.exe myRcode.R` – Bill the Lizard Aug 01 '17 at 17:32
  • No.in fact.I am using a software which it running on command prompt windows. In the part of running, it tries to invoke the system or console command with an external file. I use myRcode.R as external file. But myRcode.R is opened in Rstudio environment without running it. Actually, myRcode.R is not an executable file. myRcode.R is located in software folder. – adele Aug 01 '17 at 18:07
  • I tested. The file is located inside C:\"Program Files"\R\R-3.3.3\bin\x64\Rscript.exe myRcode.R Unfortunately, “Cannot open file “myRcode.R”: no such file or directory. – adele Aug 01 '17 at 18:23
  • Ok, in your command prompt window you need to be in the same directory with myRcode.R, or R won't be able to find it. Otherwise, you can specify the path by running `C:\"Program Files"\R\R-3.3.3\bin\x64\Rscript.exe C:\RStudio\Directory\Path\To\myRcode.R` (replacing that last bit with your actual path to your script). – Bill the Lizard Aug 01 '17 at 19:48
  • C:\XX\Rscript myRcode.R- C:\Program Files\R\R-3.3.3\bin\x64\ Rscript.exe- C:\Program Files\RStudio\bin\x64- XX is a software which it running on command prompt windows. I added C:\Program Files\R\R-3.3.3\bin\x64\ Rscript.exe to path. Please explain again. I did not understand. – adele Aug 02 '17 at 10:31
  • Does running `Rscript.exe` by itself (no path, no `myScript` file) on the command line give you the usage message? – Bill the Lizard Aug 02 '17 at 12:13
  • when i run Rscript.exe on the command line:it says 'Rscript' is not recognized as an internal or external command, operable program or batch file.' I do not know why? it is an environment variables. – adele Aug 02 '17 at 13:52
  • In your system PATH variable, it should just be `C:\"Program Files"\R\R-3.3.3\bin\x64` without the script name (Rscript.exe). It only needs the directory where executable file is, not the file itself. – Bill the Lizard Aug 02 '17 at 14:30
  • Ok.I was very thankful you are considering my problem. I changed system PATH variable and then I ran Rscript.exe by itself.The message was similar to using path. Furthermore, I tested Rscript myRcode.R by itself again and it showed an error: no such file or directory. – adele Aug 02 '17 at 15:19
  • Ok, good. Now that your PATH is fixed, you should be able to run something like `Rscript.exe C:\xxx\yyy\zzz\myRcode.R` (replacing `xxx\yyy\zzz` with the actual path to your R script. – Bill the Lizard Aug 02 '17 at 15:26
  • Alternatively, you can navigate to the directory where your script is (in your command window), then run `Rscript.exe myRcode.R` – Bill the Lizard Aug 02 '17 at 15:27
  • Running software with Rscript myRcode.R, error: the system cannot find the path specified. Running software with myRcode.R, it will open RStudio, but it does not run. Both Rscript myRcode.R and myRcode.R are located in c:\XX and XX is software folder. I cannot change place of my R code file because software will show: no such file or directory – adele Aug 02 '17 at 15:50
  • In XX software, I can only write the name of my file. Only one name for a file. – adele Aug 02 '17 at 15:55
  • If you have a file named "Rscript myRcode.R" you shouldn't. It should just be "myRcode.R". Rscript is the name of the executable file that then parses and runs your code. Try running `Rscript.exe myRcode.R` – Bill the Lizard Aug 02 '17 at 16:06
  • Unfortunately. It does not work. Error message text: no such file or directory. – adele Aug 02 '17 at 19:08
  • I am delighted to inform you that I used Rscript "c:\XX\y.R" and it worked. How to sum up Rscript "c:\XX\y.R” to a name? I added Rscript "c:\XX to environment variables but it did not work. I want to running “y.R “ – adele Aug 02 '17 at 20:13
  • It takes a lot of additional setup to do that, but you can read how here: https://www.r-bloggers.com/making-r-files-executable-under-windows/ If you only have a couple of scripts that you want to run this way, I'd probably stick with manually running them through Rscript. – Bill the Lizard Aug 02 '17 at 20:19
  • Thank you for sharing your wisdom with me.I have seen it before. When I removed Rstudio, .Rexec was correct. When I use Rstudio .Rexec is not executable R script file and for example y.Rexec will be opened in Rstudio environment.I am grateful for the positive learning environment you provided me with. – adele Aug 03 '17 at 06:54
  • 1
    Bill the Lizard, Thank you for your guidance and support.http://stackmirror.cn/page/s12ukg136l2s, Solved my last problem. – adele Aug 03 '17 at 09:33

0 Answers0