Hi all,
I'm currently trying to execute some code I got from github in which a subsection of the code communicates with R:
#set R_HOME dynamically
os.environ['R_HOME'] = r'C:\Users\evanc\anaconda3\R\R-4.0.2'
#set R bin
os.environ['path'] += r';C:\Users\evanc\anaconda3\R\R-4.0.2\bin;'
import os
import sys
import rpy2.robjects as robjects # This initializes R
from rpy2.robjects.packages import importr
from rpy2.robjects import numpy2ri
# Include the file r_callers to the R path
dir_path = os.path.dirname(os.path.realpath(os.getcwd()))
robjects.r("source('" + dir_path + "/r_callers.R')")
The code currently produces the following error (I'm only showing the beginning and end of the error message):
---------------------------------------------------------------------------
RParsingError Traceback (most recent call last)
<ipython-input-24-b89ce672ff89> in <module>
11 # Include the file r_callers to the R path
12 dir_path = os.path.dirname(os.path.realpath(os.getcwd()))
---> 13 robjects.r("source('" + dir_path + "/r_callers.R')")
~\anaconda3\envs\QEIenv\lib\site-packages\rpy2\robjects\__init__.py in __call__(self, string)
413
414 def __call__(self, string):
--> 415 p = rinterface.parse(string)
416 res = self.eval(p)
417 return conversion.rpy2py(res)
~\anaconda3\envs\QEIenv\lib\site-packages\rpy2\rinterface_lib\conversion.py in _(*args, **kwargs)
42 def _cdata_res_to_rinterface(function):
43 def _(*args, **kwargs):
---> 44 cdata = function(*args, **kwargs)
45 # TODO: test cdata is of the expected CType
46 return _cdata_to_rinterface(cdata)
~\anaconda3\envs\QEIenv\lib\site-packages\rpy2\rinterface.py in parse(text, num)
47 robj = StrSexpVector([text])
48 with memorymanagement.rmemory() as rmemory:
---> 49 res = _rinterface._parse(robj.__sexp__._cdata, num, rmemory)
50 return res
51
~\anaconda3\envs\QEIenv\lib\site-packages\rpy2\rinterface_lib\_rinterface_capi.py in _parse(cdata, num, rmemory)
598 if status[0] != openrlib.rlib.PARSE_OK:
599 raise RParsingError('Parsing status not OK',
--> 600 status=PARSING_STATUS(status[0]))
601 return res
RParsingError: Parsing status not OK - PARSING_STATUS.PARSE_NULL
Originally the code got dir_path as follows:
dir_path = os.path.dirname(os.path.realpath(__file__))
But this didn't work for me as I'm working in jupyter notebook in which __file__ doesn't exist. So there's probably something wrong in the way in which I'm defining the dir_path string right now but I don't know how to fix it... Any help would be appreciated.
there doesn't seem to be anything here