RStudio v1.2.1153-1 preview reticulate/python failure in R Notebook

Ubuntu 18.10
RStudio v1.2.1153-1
python 3.5

R-notebook

chunkStart {r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(reticulate)
use_condaenv('phylo3',conda='/home/username/local/programs/anaconda3/bin/conda',required=TRUE)
py_config()
chunkEnd

The above works fine and loads the expected python configuration

chunkStart {python}
import os
chunkEnd

Running the code above causes an R Session Aborted fatal error (with the bomb icon)

[Note that I've replaced ``` with chunkStart, chunkEnd in the R notebook chunks so that it is clear which is the R code and which the python]

hey @delphis - can you install the latest daily build and see if this behavior continues?

I downloaded RStudio today from: https://s3.amazonaws.com/rstudio-ide-build/desktop/trusty/amd64/rstudio-1.2.1153-amd64.deb
It says this one is from November 27. Is there a later one?

Always :grinning: - the version number here is 1.2.1160. It is worth a shot anyway.

https://dailies.rstudio.com

Can you test against your macOS Python installation or another install of Python to see if this is specific to Anaconda?

Can you also test and see if you can source a .py file in your RStudio session? This would indicate whether the issue lies with the .Rmd file or with something in RStudio more generally.

If your issue does not resolve, I would open an issue. For reference, here is RStudio guide for filing bug reports.

I got the same R Session Aborted error with 1160.

However, when I comment out the use_condaenv line it works (both with the built-in python2.7 and python3 if I specify which python to use). So perhaps it is a conda thing.

Using /usr/bin/python3:

I made a file called add.py and tried to source it and got the following:

Error in py_run_string_impl(code, local, convert) :
NameError: name 'source_python' is not defined


Edited: I ran source_python() in the python chunk above, not realizing it was a function in the reticulate r package. When I ran it in the r chunk it worked just fine.

@delphis
I am using reticulate in production, And I suggest you directly config the reticulate_python in your .Renviron, which will save you a lot of time

FYI, you can paste R Markdown documents as code here by enclosing them with 5 backticks, e.g.

`````

```{r}
# some R code
```

`````

That said, if the crash is occurring when attempting to load the os Python module then there is likely something funky with your Python installation.

I made a brand new conda environment and py_config() worked as did import os. So perhaps there is indeed something wrong with my previous 'phylo3' environment as kevinushey says - although I can import os perfectly well in a python interpreter.

If you wanted to get to the bottom of it, you could try attaching a debugger (e.g. gdb) to the R process, and trying to get a backtrace to see what's crashing when os is loaded. For example:


First, close any running instances of RStudio, and then launch a new lone RStudio instance.

Then, in a terminal, start GDB and have it attach to RStudio. You should be able to do this with:

sudo gdb -p `pidof rsession`

If you do not have the pidof utility installed, you can run Sys.getpid() in your R session to get the session's process ID.

After this, GDB should (hopefully) successfully attach to the process. Next, we'll instruct GDB to log to a file:

set logging file rstudio.log
set logging on

Finally, we'll tell GDB to let RStudio continue running:

continue

Now, return to your RStudio session and try running the code that triggered the crash. With luck, if RStudio crashes, GDB should catch the fault. Return to GDB, and enter:

backtrace

You should now be able to quit GDB with

quit

and then make the file at 'rstudio.log' available to us for further inspection.

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.