我在 Rstudio $version [1] ‘2023.3.0.386’
(R 版本 4.2.3
)中打开了一个新项目并启动了 renv。
启动正常运行,但是在完成 R session 后卡住。
当我重新启动 RStudio 时,R session 再次卡住。
控制台将显示以下内容:
R version 4.2.3 (2023-03-15 ucrt) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
* Project 'xx/_analysis' loaded. [renv 0.17.2-24]
当我打开没有 renv 的项目时,R 不会卡住。
我尝试过的:
我尝试删除 R 项目和 renv 文件夹并创建一个新的 R 项目,但是,我遇到了同样的错误。
更新:我现在删除了 R、Rtools 和 RStudio,并删除了所有 R 包文件并重新安装了所有内容(带有 install_github("rstudio/renv")
的 renv,如果我没有运气的话现在启动 renv::init()
,它就会挂起
如何找到可能的原因/调试?
最佳答案
感谢 polkas 评论,我可以使用 browser()
调用适本地调试 renv::init()
。
调查结果:
- 我发现同事创建的一个新项目子文件夹包含几个 100k 的 .txt 文件,renv 在其中搜索包并陷入困境
renv::init(bare=TRUE)
(即初始化项目而不尝试发现和安装 R 包依赖项)有效- 我不知道 renv 会搜索项目文件夹中的所有文件,我以为它只会搜索
.R
脚本
解决方案:
- 如果您的项目文件夹包含许多文件,则阻止
renv
扫描您的所有文件
就我而言,我写了一个 renvignore file (不包括所有.txt 文件)并将其存储在项目文件夹中。最后,renv 再次按预期工作。
默认情况下,renv 将读取项目的 .gitignores(如果存在)。您还可以创建一个 .renvignore 文件(使用 same format 条目作为标准 .gitignore 文件)。如果两个文件都存在,则将使用 renvignore。
.renvignore 文件示例:
# ignore all text files
*.txt
# ignore all data folders
data/
# ignore only data folders from the root of the project
/data/
关于R session 因 renv 0.17.2 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75912751/