Windows 7 上的 R CMD 错误 - “R”未被识别为内部或外部命令,
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10077689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
R CMD on Windows 7 Error - "R" is not recognized as an internal or external command,
提问by David Diez
I'm exploring package building on Windows 7 but have been running into trouble after reaching the Command Prompt stage. The following thread appears to be on the same topic that I'm having trouble with, but the question remains unresolved:
我正在探索在 Windows 7 上构建软件包,但在到达命令提示符阶段后遇到了麻烦。以下线程似乎与我遇到问题的主题相同,但问题仍未解决:
The problem: whenever I try an R CMD command in Command Prompt (e.g. I've tried R CMD install pkgName
, R cmd install pkgName
, Rcmd install pkgName
, where pkgName
is a place-holder for an actual package that has been R CMD check
ed on OS X and also posted on CRAN, where I have the unzipped source in the current working directory), I get the following error message:
问题:每当我在尝试的R CMD命令命令提示符(例如,我试过R CMD install pkgName
,R cmd install pkgName
,Rcmd install pkgName
,这里pkgName
是一个实际的包,已经有占位符R CMD check
的OS X版,并张贴在CRAN,在那里我有解压source 在当前工作目录中),我收到以下错误消息:
'R' is not recognized as an internal or external command,
operable program or batch file.
(If I try the Rcmd install pkgName
command, then the error starts out as 'Rcmd' is not ...
.) Note that even if I type in just R
in Command Prompt and hit enter, I get the same error, so I'm not even able to bring up R here, though it opens perfectly fine in its stand-alone interface.
(如果我尝试该Rcmd install pkgName
命令,则错误开始为'Rcmd' is not ...
。)请注意,即使我只R
在命令提示符中输入并按回车,我也会收到相同的错误,所以我什至无法在此处调出 R,不过它在其独立界面中打开得非常好。
I have examined the following guides without success in identifying the trouble:
我已经检查了以下指南,但未能成功识别问题:
The most immediate thing that came to mind was that the path variables in Windows were not set right, but this also has not (yet) led to the answer. For example, I have triple-checked the paths to ensure they are correct, including for the R version number, that x64
in the path name is accurate, etc.
想到的最直接的事情是 Windows 中的路径变量设置不正确,但这也没有(还)导致答案。例如,我对路径进行了三次检查以确保它们是正确的,包括 R 版本号、x64
路径名中的正确性等。
I realize this is a complex issue to remotely diagnose, but any advice and suggestions on resolving this trouble is appreciated. For reference, below are the steps I have taken already to try to resolve this issue:
我意识到这是一个远程诊断的复杂问题,但对解决此问题的任何建议和建议表示赞赏。作为参考,以下是我已经采取的尝试解决此问题的步骤:
- Uninstall R and Rtools
- Install the latest version of R (2.15.0)
- Install Rtools215to match R version 2.15.0
- Originally I let Rtools specify the path variables (turning that option on during installation). No success after this method.
I updated the path variables on my computer, where the below paths were used:
C:\Rtools\bin; C:\Program Files\R\R-2.15.0\bin\x64;
I've also tried the
R CMD
(andRcmd
) commands with the following paths included (note that these paths don't lead to anything on my computer, so I tried doingR CMD
/Rcmd
with and without them specified):C:\Rtools\perl\bin; C:\Rtools\MinGW\bin;
Tried adding/removing the following path, which goes to the only other folder visible within the Rtools folder:
C:\Rtools\gcc-4.6.3;
Tried multiple variations of the
R CMD
commands, as noted earlier.- I tried this all a few months ago when I had R version 2.14.1 and Rtools214 installed, and I had the exact same trouble.
- 卸载 R 和 Rtools
- 安装最新版本的R (2.15.0)
- 安装Rtools215以匹配 R 版本 2.15.0
- 最初我让 Rtools 指定路径变量(在安装过程中打开该选项)。此方法后没有成功。
我更新了计算机上的路径变量,其中使用了以下路径:
C:\Rtools\bin; C:\Program Files\R\R-2.15.0\bin\x64;
我还尝试了包含以下路径的
R CMD
(andRcmd
) 命令(请注意,这些路径不会导致我计算机上的任何内容,因此我尝试在指定和不指定它们的情况下执行R CMD
/Rcmd
):C:\Rtools\perl\bin; C:\Rtools\MinGW\bin;
尝试添加/删除以下路径,该路径转到 Rtools 文件夹中唯一可见的其他文件夹:
C:\Rtools\gcc-4.6.3;
R CMD
如前所述,尝试了命令的多种变体。- 几个月前,当我安装了 R 版本 2.14.1 和 Rtools214 时,我尝试了所有这些,但遇到了完全相同的问题。
Note: I already had Cygwin installed prior to R and Rtools, and I have not installed MikTeX (yet).
注意:我在 R 和 Rtools 之前已经安装了 Cygwin,我还没有安装 MikTeX(还)。
采纳答案by Jeff Allen
- Have you closed the command prompt and opened a new one after adjusting the PATH?
- Enter the command
PATH
on the command line and ensure that you are properly updating your path - Try navigating to the directory where R.exe is saved and running it locally --
cd C:\Program...\bin\x64
,R.exe
. - Ensure that you're running on Windows' Command Prompt and not Cygwin's terminal
- If you actually have a space after the semi-colon in your PATH, you'll need to remove that:
/bin;C:/Program...
. Try combining that with Joshua's solution.
- 你有没有在调整PATH后关闭命令提示符并打开一个新的?
PATH
在命令行输入命令并确保正确更新路径- 尝试导航到保存 R.exe 的目录并在本地运行它 --
cd C:\Program...\bin\x64
,R.exe
. - 确保您在 Windows 的命令提示符而不是 Cygwin 的终端上运行
- 如果您的 PATH 中的分号后确实有一个空格,则需要删除它:
/bin;C:/Program...
。尝试将其与 Joshua 的解决方案结合起来。
回答by Yan Zhang
I attach my whole solution here:
我在这里附上我的整个解决方案:
- Install Rtools which is compatible with my R version
- Add
PATH: C:\Program Files\R\R-2.15.1\bin\x64;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
- In cmd, enter:
R CMD INSTALL packagename
- 安装与我的 R 版本兼容的 Rtools
- 添加
PATH: C:\Program Files\R\R-2.15.1\bin\x64;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
- 在cmd中输入:
R CMD INSTALL packagename
Click "enter", done.
点击“进入”,完成。
回答by Scott I
I had a lot of trouble getting this to work, and finally found the golden nugget on r-project(R doesn't like spaces in paths) so here's how I finally did all this:
我在让它工作时遇到了很多麻烦,最后在r-project上找到了金块 (R 不喜欢路径中的空格)所以这是我最终完成所有这些的方法:
- I installed R to "c:\programs" instead of "c:\program files...". My final path to RSCRIPT.exe is "C:\Programs\R\R-2.15.2\bin\Rscript.exe"
- I added that directory to my PATH, but that doesn't seem to help
- RStudio is also installed under c:\Programs (e.g. c:\Programs\RStudio), but RTools is installed under the "c:\" root directory (e.g. c:\RTools).
- I downloaded all the packages to "c:\downloads\r"
- I opened a command prompt in "c:\downloads\r" and ran the R CMD install from this downloads directory, specifying the path to R
- e.g. "C:\Programs\R\R-2.15.2\bin\x64\R CMD INSTALL colorspace_1.2-0.zip"
- 我将 R 安装到“c:\programs”而不是“c:\program files...”。我到 RSCRIPT.exe 的最终路径是“C:\Programs\R\R-2.15.2\bin\Rscript.exe”
- 我将该目录添加到我的 PATH,但这似乎没有帮助
- RStudio 也安装在 c:\Programs(例如 c:\Programs\RStudio)下,但 RTools 安装在“c:\”根目录下(例如 c:\RTools)。
- 我将所有软件包下载到“c:\downloads\r”
- 我在“c:\downloads\r”中打开了一个命令提示符,并从此下载目录运行了 R CMD 安装,指定了 R 的路径
- 例如“C:\Programs\R\R-2.15.2\bin\x64\R CMD INSTALL colorspace_1.2-0.zip”
回答by Lester Martinez
Simple solution, use quotes:
简单的解决方案,使用引号:
c:> "C:\Program Files\WinZip\wzunzip.exe"
c:> "C:\Program Files\WinZip\wzunzip.exe"
if you run this, you don't need to worry about the space in Program Files.
如果你运行它,你就不需要担心 Program Files 中的空间。
Hope this help.
希望这有帮助。
回答by Pragyaditya Das
I encountered a similar problem while trying to use SparkR from Windows Power Shell. Each time I would do ".\sparkR.cmd" (I was inside the folder containing this file), it would throw an error message like,
我在尝试从 Windows Power Shell 使用 SparkR 时遇到了类似的问题。每次我执行“.\sparkR.cmd”(我在包含此文件的文件夹中)时,它都会抛出一条错误消息,例如,
cmd is not recognized as an internal and external command...blah...blah...blah.
cmd 不被识别为内部和外部命令......等等......等等......等等。
I solved the problem by adding "C:\Windows\System32" to my PATH.
我通过在路径中添加“C:\Windows\System32”解决了这个问题。
I restarted my system and then repeated the process and this time, I saw a new error,
我重新启动了我的系统,然后重复了这个过程,这一次,我看到了一个新的错误,
R is not recognized as an internal and external command...blah...blah...blah.
R 不被识别为内部和外部命令......等等......等等......等等。
I tried all sorts of approaches, including the ones mentioned above. NOTHING WORKED, I was probably wasn't efficient enough to make it work.
我尝试了各种方法,包括上面提到的方法。没有任何效果,我可能没有足够的效率让它工作。
Then I came across this place at code.google. I simply copied the R.bat onto a notepad, named it as R.bat. Kept it inside the folder where sparkR.cmdwas located. For me it was,
然后我在 code.google遇到了这个地方。我只是将 R.bat 复制到记事本上,将其命名为 R.bat。将它保存在sparkR.cmd所在的文件夹中。对我来说是,
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\
The I placed it on my PATH as :
我把它放在我的 PATH 中:
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\R.bat
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\R.bat
Restarted my laptop, opened my Power Shell as an administrator and typed :
重新启动我的笔记本电脑,以管理员身份打开我的 Power Shell 并输入:
.\R.bat help
.\R.bat 帮助
It worked fine. Then I typed,
它工作得很好。然后我打字,
.\sparkR.cmd
.\sparkR.cmd
and there it was.
就在那里。
It worked.
有效。
I hope it helps to people new to R. Thank you G. Grothendieck.
我希望它对 R 的新手有所帮助。谢谢 G. Grothendieck。
回答by Javamann
It appears that the CMD processor is Case Sensitive. You have to use INSTALL vs. install
CMD 处理器似乎是区分大小写的。您必须使用 INSTALL 与安装
回答by Anmol Arora
In the .bat file add a line of code specifying the path of the folder where R is installed and then give the path of the script as follows -
在 .bat 文件中添加一行代码,指定安装 R 的文件夹的路径,然后给出脚本的路径,如下所示 -
@ECHO OFF
PATH C:\Program Files\R\R-3.5.1\bin
R CMD BATCH D:\project_abc\helloworld.R
Following this, run the .bat file and you will see the code in the script will run smoothly.
在此之后,运行 .bat 文件,您将看到脚本中的代码将顺利运行。