RStudio crashes during start-up when package 'reticulate' is installed

Hi @all!

I updated RStudio to version 1.4 and ever since RStudio (or R) generates fatal errors during start-up. This only happens when the package reticulate is installed. When I remove that package RStudio boots without any errors.

Here's the log-file (sorry for the German output):

20 Jan 2021 08:54:50 [rsession-XXX] ERROR r error 4 (R code execution error) [errormsg: Error in .Call(method, prefName, PACKAGE = "(embedding)") : 
  'rs_readUserPref' ist nicht verfügbar für .Call() aus Paket "(embedding)"
]; OCCURRED AT class rstudio::core::Error __cdecl rstudio::r::exec::evaluateString(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,struct SEXPREC **,class rstudio::r::sexp::Protect *,enum rstudio::r::exec::EvalFlags) src/cpp/r/RExec.cpp:337; LOGGED FROM: int __cdecl rstudio::r::session::RReadConsole(const char *,char *,int,int) src/cpp/r/session/RStdCallbacks.cpp:297
20 Jan 2021 08:55:38 [rsession-XXX] ERROR r error 4 (R code execution error) [errormsg: Error in .Call(method, prefName, PACKAGE = "(embedding)") : 
  'rs_readUserPref' ist nicht verfügbar für .Call() aus Paket "(embedding)"
]; OCCURRED AT class rstudio::core::Error __cdecl rstudio::r::exec::evaluateString(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,struct SEXPREC **,class rstudio::r::sexp::Protect *,enum rstudio::r::exec::EvalFlags) src/cpp/r/RExec.cpp:337; LOGGED FROM: int __cdecl rstudio::r::session::RReadConsole(const char *,char *,int,int) src/cpp/r/session/RStdCallbacks.cpp:297
20 Jan 2021 08:57:12 [rsession-XXX] ERROR CLIENT EXCEPTION (rsession-XXX): (TypeError) : Cannot read property 'L' of null;
org/rstudio/studio/client/workbench/views/source/editors/text/AceEditor.java#4486::setScrollSpeed
org/rstudio/studio/client/workbench/views/source/editors/text/AceEditorMonitor.java#46::monitor
org/rstudio/studio/client/workbench/views/source/editors/text/AceEditorMonitor.java#70::execute
com/google/gwt/core/client/impl/SchedulerImpl.java#140::execute
com/google/gwt/core/client/impl/Impl.java#306::apply
com/google/gwt/core/client/impl/Impl.java#345::entry0
rstudio-0.js#-1::eval
com/google/gwt/cell/client/AbstractEditableCell.java#41::viewDataMap
Client-ID: 33e600bb-c1b1-46bf-b562-XXX
User-Agent: Mozilla/5.0 (Windows NT 10.0  Win64  x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36

Thanks a lot for your help!

4 Likes

Any updates here? I am having the same problem after updating to MAC OS 11.1 and RStudio 1.4.

Also having the same issue when attempting to upgrade to RStudio 1.4. Using R 4.0.3 and Windows 10 Home Edition, 64 bit.

It causes complete failure of Rstudio, not just R. That is, source pane, console pane, toolbars etc don't show up. Just the error.

I updated RStudio to version 1.4 and ever since RStudio (or R) generates fatal errors during start-up. This only happens when the package reticulate is installed. When I remove that package RStudio boots without any errors.

My guess is that reticulate was built against an earlier version of R which is not compatible w/the version on your machine. From my experience w/R on a Mac, I wrote some specific diagnostic instructions that may be helpful. Please see GitHub - dgabbe/rprofile.site: Rprofile.site and .Renviron files plus installer scripts.

update.packages(ask = FALSE, checkBuilt = TRUE) will update packages as needed. However I have not used it in combination with packrat or renv.

Since the problem goes away when reticulate is removed from your R library, I've assumed for the moment that the problem is not on the Python side.

Thanks for the hint. I have already made several removals and fresh installs of package reticulate because my initial thought was the same as yours. It doesn't help.

I can add a further observation: I am running an almost identical set-up of R and RStudio on my MacBook Pro and on my Windows 10 machine. The problem occurs only in the Windows 10 environment. No problems with the Mac (as always...).

1 Like

I updated RStudio to version 1.4 and ever since RStudio (or R) generates fatal errors during start-up.

Rereading your sentence above, I want to confirm that if you run the R app (equivalent of /Applications/R.app on the Mac), you get the fatal error during R's initialization sequence. If yes, what's the error?

If no, then I would speculate the problem is w/RStudio. If you use the previous version of RStudio, does it successfully boot?

The last time I did anything w/Windows, I used the Chocolately package manager. It looks like there are a number of R distributions available so I wonder if RStudio works w/a different R install. What I like about Chocolately is it makes it much easier to mess around w/different packages, analogous to homebrew on the Mac.

A quick scan of reticulate issues turned up issue #921 w/an interesting solution. No idea if it will help you, but seems worth a try.

Thanks! It definitely is a problem in the interplay of RStudio 1.4 and reticulate. R itself seems to work fine - even if I use reticulate(outside RStudio). I'll have a look into issue #921.

1 Like

Just wanted to chime in and say I have the same problem after updating to Rstudio 1.4 on both Windows 10 and Ubuntu 20.04. The problem seems to occur when the type parameter in renv::use_python() is set to "conda". Setting it to "system" or "virtualenv" solves the problem. I'm guessing this is why it works on your mac and not Windows (since by default the type parameter is set to virtualenv for Mac).

I've looked through the use_python source code but I'm not able to trace the error message back to some call in the code.

Hi. Thanks to the comment from @mafw about renv I was able to fix this in my case. I had put the following line in my .Rprofile for other reasons:

 reticulate::use_condaenv("env1", required = TRUE)

Removing this line and reinstalling reticulate seemed to do this trick. Curiously, I can still run this line in the R session without error so I'm not sure what the issue is. Thanks everybody!

3 Likes

Thanks @jackvanschaik . I had a similar line in my .Rprofile and removing it fixed the problem.

1 Like

Interestingly, the problem seems to occur when reticulate is auto-loaded via .Rprofile.

Here's a snippet from my .Rprofile file:

[...]
if(Sys.info()[[1]] == "Windows") {
  auto.loads <-c(
    "utils",
    "conflicted",
    "reticulate",
    "tidyverse",
    "rmarkdown",
    "knitr",
    "readxl",
    "broom",
    "crayon")
} else {
  auto.loads <-c()
}

if(interactive()){
 invisible(sapply(auto.loads, sshhh))
}
[...]

If I remove reticulate from the list of packages above RStudio starts up flawlessly. I can then load reticulate without any problems. For some reason RStudio produces a hick-up when the package is loaded automatically.

Based on the discussion here it seems like Rstudio has some issues loading conda environments when starting. I was able to recreate the problem @edlerito mentions by including library(reticulate) in my .Rprofile file. I'm guessing it is a conda problem because it causes no problems when I run it on my Mac.

Not only conda. I haven't even installed conda on my machine. I'm using the regular Python distribution (3.9.1 in the current set up).

That's strange. Then I'm guessing it's just a Windows problem (isn't it always).

2 Likes

It's not just a Windows problem -- I get the same error on my machine, running Ubuntu. The line

reticulate::use_python('/usr/bin/python3')

in my .Rprofile file prevents Rstudio from loading. R loads fine, and Rstudio loads fine if I comment the line out.

Interesting! On my Ubuntu 20.04 system I just tried including reticulate::use_python('/usr/bin/python3') in my user .Rprofile and Rstudio crashed. The same happens if I point reticulate to any of my virtual environments....

Fortunately it's possible to circumvent this issue by instead setting the system variable sys.setenv(RETICULATE_PYTHON = PATH) in the .Rprofile. This achieves the same result as reticulate::use_python(PATH_TO_PYTHON)

So it seems that maybe there are some issues with Rstudio loading python using reticulate on startup? I've had problems using renv to keep track of my python environments and now I'm thinking that this might be because renv calls reticulate::use_python at startup.

Hi,

I'm having the same issues on a macOS 11.2.2 system. I can effectively reproduce the problem by enabling or disabling renv in a project. I've been trying both conda environments and "plain" virtualenv's made with pyenv and virtualenvwrapper, same result.

Presently, I am not able to run any Python in RStudio: even if I avoid renv, when I run matplotlib I get the same bug described in this RStudio Github issue — shown here in a loom.

I'm having the same issue when using reticulate with renv.

I'm able to load my project if I comment out source("renv/activate.R") in my .Rprofile. Then I can run renv::load() and everything works as expected.

Windows 10 x64, Build 17134
RStudio Version 1.4.1106
R version 4.0.4 (2021-02-15) -- "Lost Library Book"
renv 0.13.0
reticulate 1.18-9007
conda 3.8.6

This thread is more interesting now because I just created my first Rmarkdown doc that included Python code. .Rprofile is run early in the R startup machinery. For those who reported including code in this file, is it in the .First function? Does moving it into .First change the behavior.

Another workaround to consider is using both Rprofile.site and .Rprofile. They load in the order listed.

@mafw
~/.Renviron can also be used to set R's environment variables. I prefer this method to keep all my R stuff together, separate and independent from my shell environment. Contrary to some comments in Stack Overflow, this works for RStudio, R.app, and command line R.