5

I just installed R on a new Microsoft Windows 7 computer and I am running in the following error when using command line:

"C:\Program Files\R\R-3.3.2\bin\Rscript.exe" --version  
'C:\Program' is not recognized as an internal or external command,

operable program or batch file.

Note that I have added above the quotes around the path with a space. And that I have added in the system path:

;C:\Program Files\R\R-3.3.2\bin\

Interestingly:

  1. if I just call this Rscript.exe --version it gives the same error, which is very weird: if it finds it, why can't it run it!?! The only explanation I can find is that the error occurs when looking for a dependency of Rscript.exe
  2. I also noticed that this works "C:\Program Files\R\R-3.3.3\bin\x64\Rscript.exe" --version (both folders ...\bin and ...\bin\x64 have an executable Rscript.exe)

Finally I confirm it is an R specific question as all other executables I tried in a subfolder of Program Files can be called through the same command line interface!

RockScience
  • 17,932
  • 26
  • 89
  • 125
  • 1
    Your Q title seems unrelated to your Q? – MichaelChirico Oct 13 '17 at 09:54
  • @MichaelChirico It's not really an R question :-) – Tim Biegeleisen Oct 13 '17 at 09:56
  • 1
    Cannot reproduce this. Calling `>"C:\Program Files\R\R-3.3.3\bin\Rscript.exe" --version` resulted into `R scripting front-end version 3.3.3 (2017-03-06)` – Heikki Oct 13 '17 at 10:00
  • @Heikki you are lucky! – RockScience Oct 13 '17 at 10:24
  • guys you are voting to close but my question is valid... and documented. If anything needs to be improved in the title you can suggest or edit – RockScience Oct 13 '17 at 10:31
  • Have you restarted cmd after updating environment path? And after only after that tried to run `Rscript.exe --version` ? – Heikki Oct 13 '17 at 10:55
  • I reproduced the error by forgetting the first quotation mark: `>C:\Program Files\R\R-3.4.1\bin\Rscript.exe" --version` resulted into `'C:\Program' is not recognized as an internal or external command,` – Heikki Oct 13 '17 at 10:58
  • @Heikki Indeed... But in my case, I have not forgotten it ;) – RockScience Oct 16 '17 at 01:03
  • Do you get the same error if you run `cmd /K "C:\Program Files\R\R-3.3.1\bin\Rscript.exe" --version` – Heikki Oct 16 '17 at 11:02
  • @Heikki yes same error. However I noticed that this works `"C:\Program Files\R\R-3.3.3\bin\x64\Rscript.exe" --version` works... (both folders `...\bin` and `...\bin\x64` have an executable Rscript.exe) – RockScience Oct 16 '17 at 11:09
  • @TimBiegeleisen actually it is because with any other executable it works. It seems specific to R. – RockScience Oct 16 '17 at 11:16
  • Some progress.. Just to make sure, do you want to use `Rscript.exe` to run a R command or file from command line, and not the `R.exe` to use the frontend? RStudio seems to be calling R.exe and not Rscript.exe. – Heikki Oct 16 '17 at 11:26
  • @Heikki yes confirming I need to execute a R script through command line – RockScience Oct 16 '17 at 15:52
  • So if you can live with running only the 64-bit or 32-bit version on R, then in principle you have a solution. What about trying a newer version on R? – Heikki Oct 17 '17 at 08:07
  • Somewhat related to [R FAQ 2.2](https://cran.r-project.org/bin/windows/base/rw-FAQ.html#How-do-I-install-R-for-Windows_003f) but very heavily based on my experience (similar to yours), I install my R directly under `c:\R\R-3.3.3\...`; a space in the R path confounded me for weeks until I just buckled and fixed the symptom. It might also live just fine in a directory under `c:\Users\yourusername\`, assuming your username has no spaces. – r2evans Oct 17 '17 at 18:04
  • Do you have both version 3.3.2 and version 3.3.3 installed? – Sheldon Oct 18 '17 at 11:15
  • Are you copying the line `"C:\Program Files\R\R-3.3.2\bin\Rscript.exe" --version` from somewhere? In that case it could be an encoding problem. – Anwar Shaikh Oct 23 '17 at 15:37

2 Answers2

2

I have been trying to replicate your issue and I found one thing in your question: You mention that this does not work:

"C:\Program Files\R\R-3.3.2\bin\Rscript.exe" --version  
'C:\Program' is not recognized as an internal or external command,

But this does:

"C:\Program Files\R\R-3.3.3\bin\x64\Rscript.exe" --version

It seems that you are using R-3.3.3 in the example that works and R-3.3.2 in the example that does not.

So I would assume that if you change it to

"C:\Program Files\R\R-3.3.3\bin\Rscript.exe" --version  

it should work.

clemens
  • 6,653
  • 2
  • 19
  • 31
0

Check out

C:\Users>Rscript --help
Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]

--options accepted are
  --help              Print usage and exit
  --version           Print version and exit
  --verbose           Print information on progress
  --default-packages=list
                      Where 'list' is a comma-separated set
                        of package names, or 'NULL'
or options to R, in addition to --slave --no-restore, such as
  --save              Do save workspace at the end of the session
  --no-environ        Don't read the site and user environment files
  --no-site-file      Don't read the site-wide Rprofile
  --no-init-file      Don't read the user R profile
  --restore           Do restore previously saved objects at startup
  --vanilla           Combine --no-save, --no-restore, --no-site-file
                        --no-init-file and --no-environ

'file' may contain spaces but not shell metacharacters
Expressions (one or more '-e <expr>') may be used *instead* of 'file'
See also  ?Rscript  from within R

Pursuing your theory that some dependency is at fault, I hoped that --verbose would indicate what other files Rscript tries to read. No such luck.

Incidentally, almost none of these options are usable for me unless I provide Rscript with some commands as well -- otherwise it keeps complaining "file name is missing". So with any of these possibilities, you can go with something like

C:\Users>Rscript --verbose -e print(2+2)

That being said, you might further pursue your theory by using the options like --no-environ, --no-site-file, --vanilla, etc., to make it skip any file dependencies and see if it gets you somewhere.

David Kaufman
  • 989
  • 1
  • 7
  • 20