microsoft / microsoft-r-open

Microsoft R Open Source
212 stars 69 forks source link

Making MRO work with rpy2 #22

Closed jlopezpena closed 5 years ago

jlopezpena commented 7 years ago

I am trying to use MRO from python using rpy2, and encountering some issues.

First, rpy2 does not find the R libraries out of the box; this can be solved by setting up the environment variables LD_LIBRARY_PATH and R_HOME before installing rpy2

export LD_LIBRARY_PATH=/usr/lib64/microsoft-r/3.3/lib64/R/lib
export R_HOME="/usr/lib64/microsoft-r/3.3/lib64/R"

after doing this, rpy2 installs and run mostly fine (if it was installed before setting the environment libraries, it must be removed and installed again!). Perhaps this should be added to the documentation somewhere?

Secondly, after installing rpy2 I get constant warnings coming from the R side, concerning the RevoUtilsMath pacakge and some getThreads method:

from rpy2 import robjects as ro

/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning: Warning messages:

  warnings.warn(x, RRuntimeWarning)
/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning: 1: 
  warnings.warn(x, RRuntimeWarning)
/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning: In value[[3L]](cond) :
  warnings.warn(x, RRuntimeWarning)
/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning: 

  warnings.warn(x, RRuntimeWarning)
/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning:  "getThreads" not available for .C() for package "RevoUtilsMath"

  warnings.warn(x, RRuntimeWarning)
/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning: 2: 
  warnings.warn(x, RRuntimeWarning)
/home/javier/anaconda2/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:185: RRuntimeWarning: 3: 
  warnings.warn(x, RRuntimeWarning)

I don't know if it is related to this warning, but when running long R processes from python they randomly die (from jupyter I just get a Kernel has died message, without any error I can trace back). I am not sure what is causing this, as it seem to happen randomly. I am guessing some race condition, or the multithreaded libraries not playing nice with rpy2.

Any ideas on how I could debug/fix this issue?

ddavidebor commented 7 years ago

Isn't this version of R mostly optimized for intel chips?

jlopezpena commented 7 years ago

I am using a computer with an intel processor, that has nothing to do with my issue.

ddavidebor commented 7 years ago

Woops sorry i though you were trying to compile for the raspberry pi!

richcalaway commented 7 years ago

I would try using setMKLthreads(1) in your R code to keep the MKL from trying to use multiple threads; see if this helps.

Cheers, Rich Calaway Microsoft R Product Team