问题
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:
- 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 - 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!
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/46727058/issue-when-calling-executable-in-a-path-that-has-space