2

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?

ava
  • 840
  • 5
  • 19
  • 1
    May I (strongly) suggest that you update to the most recent version of RStudio IDE? `1.4.1106` is [over two years old](https://docs.posit.co/ide/news/#rstudio-1.4.1106-5), the current release is 2023.03.0, available here: https://posit.co/downloads/ – r2evans Apr 02 '23 at 18:20
  • Sorry I was wrong. Because the r session was stuck again I just googled RStudio and copy pasted the first hit I had because I just downloaded it before. However it was not the link where I actually downloaded it. I checked it in the console now and it is RStudio version `2023.3.0.386` – ava Apr 02 '23 at 19:05
  • Hindsight is 20/20, but ..... if you want credibility in questions you ask here, you need to give what you actually _have_ verified via _local means_, not googling and finding a reasonable-looking version number and pasting it in hoping to fill out your question. To know what you _actually have_: in windows, go to *Settings > Apps > Installed apps* and look for the application there. If it is not listed, or just as an alternative, look at the `C:/Program Files/RStudio/VERSION` file. It's very frustrating to spend time on a question where the question itself misrepresents reality. – r2evans Apr 02 '23 at 19:16
  • Yes, that is true. I would usually always look it up in the console directly. But since my console is stuck all the time I could not do that. Thank you for these workarounds. – ava Apr 02 '23 at 19:22
  • 2
    I recommend running the R -e "renv::init()" in the terminal as RStudio often hides error messages. The most professional way to debug the problem is to git clone the repository and put the `browser()` call at the top of the renv::init function and rebuild and install the renv package. When you run the renv::init with such a new renv package then you can go line by line and checkout where it is stuck. Possibly the step with rebuilding and installing has to be repeated as the browser has to be put in some internal functions. – polkas Apr 02 '23 at 20:32

2 Answers2

4

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/
ava
  • 840
  • 5
  • 19
0

Try options(renv.download.override = utils::download.file)

Similar issue : https://community.rstudio.com/t/cant-install-packages-with-renv/96696

Phil
  • 7,287
  • 3
  • 36
  • 66
LZL
  • 91
  • 5
  • https://community.rstudio.com/t/cant-install-packages-with-renv/96696 reports a problem where packages will not be installed. In my case packages are being installed – ava Apr 02 '23 at 15:11
  • With `options(renv.download.override = utils::download.file` `renv::init()` gets stuck – ava Apr 02 '23 at 15:35