简体   繁体   English

如何确保 Rstudio 可以找到 Rtools?

[英]how to ensure Rstudio can find Rtools?

My R version is 4.2.1, Rstudio version 2022.07.1 build 554 Rtools 4.2我的 R 版本是 4.2.1,Rstudio 版本是 2022.07.1 build 554 Rtools 4.2

/c/Program Files/R/R-4.2.1/bin/x64:/c/rtools42/usr/bin are added in PATH in both system and user. /c/Program Files/R/R-4.2.1/bin/x64:/c/rtools42/usr/bin 在系统和用户的 PATH 中添加。

In Rstudio, pkgbuild::find_rtools() [1] TRUE在 Rstudio 中,pkgbuild::find_rtools() [1] TRUE

Sys.which("make")
                              make 
"C:\\rtools42\\usr\\bin\\make.exe" 
> Sys.getenv("PATH")
[1] "C:\\rtools42/x86_64-w64-mingw32.static.posix/bin;C:\\rtools42/usr/bin;C:\\rtools42/usr/bin;C:\\Program Files\\R\\R-4.2.1\\bin\\x64;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Interactive Intelligence\\ININ Trace Initialization\\;C:\\Program Files (x86)\\Interactive Intelligence\\ICUserApps\\;C:\\Program Files\\Interactive Intelligence\\ICUserApps\\;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\DTS\\Binn\\;C:\\Program Files\\Azure Data Studio\\bin;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Docker\\Docker\\resources\\bin;C:\\ProgramData\\DockerDesktop\\version-bin;C:\\Program Files\\Git\\cmd;C:\\Program Files\\R\\R-4.2.1\\bin\\x64;C:\\rtools42\\usr\\bin;C:\\Users\\fzhu\\Miniconda3;C:\\Users\\fzhu\\Miniconda3\\Library\\mingw-w64\\bin;C:\\Users\\fzhu\\Miniconda3\\Library\\usr\\bin;C:\\Users\\fzhu\\Miniconda3\\Library\\bin;C:\\Users\\fzhu\\Miniconda3\\Scripts;C:\\Users\\fzhu\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\fzhu\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\fzhu\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\fzhu\\Anaconda3\\condabin;C:\\Program Files\\R\\R-4.2.1\\bin\\x64;C:\\rtools42\\usr\\bin;;C:/Program Files/RStudio/bin/quarto/bin"

Basically i have exact problem https://community.rstudio.com/t/rstudio-cannot-find-rtools/60007基本上我有确切的问题https://community.rstudio.com/t/rstudio-cannot-find-rtools/60007

when build any source package, i got non-zero exit当构建任何源 package 时,我得到非零退出

install.packages("jsonlite", type="source")
Installing package into ‘C:/Users/fzhu/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/jsonlite_1.8.0.tar.gz'
Content type 'application/x-gzip' length 1051625 bytes (1.0 MB)
downloaded 1.0 MB

& was unexpected at this time.
Warning in install.packages :
  installation of package ‘jsonlite’ had non-zero exit status

This happens no matter use command line or build from menu.无论使用命令行还是从菜单构建都会发生这种情况。

Also since the Rstudio cannot find the Rtools, if use menu, it will ask you to redownload the Rtools42.另外由于 Rstudio 找不到 Rtools,如果使用菜单,它会要求您重新下载 Rtools42。 But after that, build still fails.但在那之后,构建仍然失败。 I wish the Rtools can automatically add tools path to environment.我希望 Rtools 可以自动将工具路径添加到环境中。

Thanks for help!感谢帮助!

reference:参考:

As @MrFlick pointed out, when install package, the error & was unexpected at this time.正如@MrFlick 指出的那样,在安装 package 时,此时的错误& was unexpected at this time. is not caused by rtools.不是由 rtools 引起的。 The package installation on windows rely on a command prompt. windows 上的 package 安装依赖于命令提示符。 However, the command prompt can not be started.但是,无法启动命令提示符。 ( window disappear after issue a cmd in search window. ) ( window 在搜索 window 中发出 cmd 后消失。)

@MrFlick referred link, cmd.exe throws error "& was unexpected at this time." @MrFlick 提到的链接, cmd.exe 抛出错误“&此时意外。” , provided problem diagnosis and solution. ,提供问题诊断和解决方案。

  • diagnosis Although I cannot start cmd prompt directly, I can still use vs code terminal to run dos commands.诊断虽然不能直接启动cmd提示符,但是还是可以用vs code终端运行dos命令。 below is the following command,下面是以下命令,
Get-ItemProperty -ea Ignore ('HKCU:', 'HKLM:' -replace '$', '\Software\Microsoft\Command Processor') AutoRun  

AutoRun      : if exist & if exist "C:\Users\fzhu\Miniconda3\condabin\conda_hook.bat"
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\Command Processor       
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft
PSChildName  : Command Processor
PSDrive      : HKCU
PSProvider   : Microsoft.PowerShell.Core\Registry

This shows cmd shell has autorun commands attached by miniconda3这表明 cmd shell 具有由 miniconda3 附加的自动运行命令

  • solution then issue command to remove these解决方案然后发出命令删除这些
Get-ItemProperty -ea Ignore ('HKCU:', 'HKLM:' -replace '$', '\Software\Microsoft\Command Processor') AutoRun |  Remove-ItemProperty -Name AutoRun

After that, my cmd prompt is back.之后,我的 cmd 提示又回来了。

And immediately, the installation error & was unexpected at this time.马上,安装错误& was unexpected at this time. disappeared.消失了。

Last note, I think this issue is very rare, but might be helpful to add "check cmd prompt shell function properly" into the R build library instructions. Last note, I think this issue is very rare, but might be helpful to add "check cmd prompt shell function properly" into the R build library instructions. The error is very elusive and hard to figure out.这个错误非常难以捉摸,很难弄清楚。

Again, thanks MrFlick!再次感谢弗利克先生!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM