部署RStudio Connect时安装BH包卡住失败求助
问题描述
我尝试将应用发布到RStudio Connect,但在Installing BH (1.84.0-0)步骤无限卡顿后失败,本地安装该包也无法成功。以下是我的sessionInfo和部署日志:
Session Info
> sessionInfo() R version 4.3.2 (2023-10-31) Platform: x86_64-apple-darwin20 (64-bit) Running under: macOS Sonoma 14.3.1 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
部署日志
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib: 'curl' call had nonzero exit status curl: HTTP 000 https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz curl: (28) Connection timed out after 10001 milliseconds curl: HTTP 000 https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz curl: (28) Connection timed out after 10001 milliseconds curl: HTTP 000 https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz curl: (28) Connection timed out after 10001 milliseconds curl: HTTP 000 https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz curl: (28) Connection timed out after 10001 milliseconds curl: HTTP 000 https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz curl: (28) Connection timed out after 10001 milliseconds FAILED Error in getSourceForPkgRecord(pkgRecord, srcDir(project), availablePackagesSource(repos = repos), : Failed to retrieve package sources for BH 1.84.0-0 from CRAN (internet connectivity issue?) Unable to fully restore the R packages associated with this deployment. Please review the preceding messages to determine which package encountered installation difficulty and the cause of the failure. Warning message: In packrat::restore(overwrite.dirty = TRUE, prompt = FALSE, restart = FALSE) : The most recent snapshot was generated using R version 4.3.2 Error code: r-cannot-access-repo RStudio Connect cannot download a package because the R package repository (for example, CRAN or RStudio Package Manager) cannot be accessed. Possible causes: * There is a network problem preventing the Connect server from connecting to the package repository. * The package repository may be down. * The package repository must be accessed through a proxy server, but no proxy server is configured in the Connect configuration file. * The client computer that published the content is using a different package repository from the Connect server, and that package repository is not accessible from the Connect server. * The package repository has moved to a different URL since the content was published. Possible solutions: * Verify that the package repository is reachable from the Connect server. * If necessary, change the Packages.HTTPProxy and Packages.HTTPSProxy configuration settings to point to your outbound proxy server. * Configure the client with a package repository that is accessible via http(s) from the Connect server, such as CRAN or RStudio Package Manager. Reinstall the affected packages from the new repository and publish the content again. Additional data: Package: 'BH' PackageVersion: '1.84.0-0' Packages.HTTPProxy: 'ltx1-itpxy.XXXX.XXX:XXXX' Packages.HTTPSProxy: 'ltx1-itpxy.XXXX.XXX:XXXX' Found in the following log entry: curl: (28) Connection timed out after 10001 milliseconds Build error: RStudio Connect cannot download a package because the R package repository (for example, CRAN or RStudio Package Manager) cannot be accessed. (r-cannot-access-repo) ── Deployment complete ───────────────────────────────────────────────────────── ✖ Deployment failed with error: RStudio Connect cannot download a package because the R package repository (for example, CRAN or RStudio Package Manager) cannot be accessed. (r-cannot-access-repo)
解决方案
从日志判断,核心问题是网络连接超时导致无法从CRAN获取BH包,可按以下步骤排查解决:
测试服务器网络连通性
- 在RStudio Connect服务器上执行命令
curl -v https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz,确认是否能正常下载包文件。 - 如果无法访问,先排查服务器防火墙、路由规则,确保出站流量能到达CRAN服务器。
- 在RStudio Connect服务器上执行命令
校验代理配置有效性
- 日志显示已配置代理,但仍超时。在服务器上用代理测试:
curl -x ltx1-itpxy.XXXX.XXX:XXXX -v https://cran.rstudio.com/src/contrib/Archive/BH/BH_1.84.0-0.tar.gz - 确认代理是否需要用户名/密码认证,若需要,需在RStudio Connect配置文件中添加对应认证参数。
- 检查代理是否允许访问CRAN的HTTPS地址,部分代理会限制特定域名或端口。
- 日志显示已配置代理,但仍超时。在服务器上用代理测试:
本地预安装BH包再部署
- 手动下载BH_1.84.0-0.tar.gz包文件,本地执行安装命令:
install.packages("本地包文件路径", repos = NULL, type = "source") - 更新项目的packrat快照后重新发布,让Connect优先从本地快照读取包,避免远程下载。
- 手动下载BH_1.84.0-0.tar.gz包文件,本地执行安装命令:
更换CRAN镜像地址
- 本地设置国内稳定镜像:
options(repos = c(CRAN = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/")),重新安装BH包。 - 在RStudio Connect配置文件中设置全局镜像地址,确保服务器使用可访问的镜像源。
- 本地设置国内稳定镜像:
内容的提问来源于stack exchange,提问作者FakeSake
相关产品推荐
相关产品推荐

