Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R session freezes with renv 0.17.2

Tags:

r

rstudio

renv

I opened a new project in Rstudio $version [1] ‘2023.3.0.386’ (R version 4.2.3) and initiated renv.

The initiation runs normally, however, after finishing the R session freezes.

When I restart RStudio the R session freezes again.

The console will show the follwoing:

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]

R will not freeze when I open a project without renv.

What I tried:

I tried to delete the R project and renv folder and made a new R project, however, I got the same error.

Update: I now deleted R, Rtools and RStudio and deleted all R package files and reinstalled everything (renv with install_github("rstudio/renv"), with no luck, if I start renv::init() now, it will just hang

How can I find possible causes/debug?

like image 615
ava Avatar asked Nov 15 '25 22:11

ava


1 Answers

Thanks to polkas comment I could debug renv::init() appropriatly using the browser() call.

Findings:

  • I found that a new project subfolder created by a collegue contained a few 100k .txt files and that renv searched them for packages and got stuck
  • renv::init(bare=TRUE) (i.e. initialize the project without attempting to discover and install R package dependencies) worked
  • I was not aware that renv searches all files in the project folder, I thought it would only search .R scripts

Solution:

  • Prevent renv from scanning all your files if your project folder contains many files

In my case, I wrote a renvignore file (excluding all .txt files) and stored it in the project folder. Finally, renv works again as expected.

By default, renv will read your project's .gitignores (if present). You can also create a .renvignore file (with entries of the same format as a standard .gitignore file). If both files are present, the renvignore will be used.

Example of a .renvignore file:

# ignore all text files
*.txt

# ignore all data folders
data/

# ignore only data folders from the root of the project
/data/
like image 192
ava Avatar answered Nov 17 '25 20:11

ava