Skip to content Skip to sidebar Skip to footer

RPY2 3.3.5 Errors On Import

I am using PyCharm and running the following code: import numpy as np import pandas as pd import rpy2.robjects.packages as packages print('TEST') I get the following error: R[wri

Solution 1:

I have run into the same issue and after extensive research and a lot of trial and error, I have two solutions:

  1. If you can use a Jupyter notebook (even in Pycharm), the cons memory exhausted error will not happen when importing rpy2 modules.

  2. If you need to use the Python console in Pycharm when running your code importing rpy2 modules and want to avoid this error, there is a workaround I use. I noticed that this error may happen due to an active renv environment set up for R in the same project. When R is set up in the same project with Python together with renv dependency management, there is a .Rprofile file in the root folder to activate renv for new R sessions. When the code is not executed (e.g. commented out) when importing an rpy2 module then there is no memory exhaust error. Once the rpy2 module is imported, renv can be activated again and all rpy2 code will execute as normal. Moreover, rpy2 can be directed to the renv environment to use packages from R project dependencies. To summarise the steps to the workaround, I wrote a function that: 1. opens .Rprofile and comments out all code 2. using Python's importlib I import the necessary rpy2 module 3. set the R_LIBS_USER environment variable to the path of the renv library path 4. remove the commenting from .Rprofile file. I will put this code on my Github later.


Solution 2:

Try to removed all files generated by RStudio in your directory.


Post a Comment for "RPY2 3.3.5 Errors On Import"