As the title says, I have a Python script that uses Rpy2 and imports an R file.
R file contents (named r_code.R):
test_function <- function(A)
{
A <- as.vector(A)
return(list(SUM=sum(A)))
}
Python file contents (named rpy2_test.py):
import numpy as np
import rpy2.robjects as robjects
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
robjects.r('''source('r_code.R')''')
r_test_function = robjects.globalenv['test_function']
def py_test_function(a):
mc = r_test_function(a)
return mc[0]
a = np.array([1,2,3,4,5])
mc = py_test_function(a)
print mc[0]
Both files are in the same directory. I type "python rpy2_test.py" and this is my error:
Error in readLines(file, warn = FALSE) : 5 arguments passed to .Internal(readLines) which requires 6 Traceback (most recent call last): File "rpy2_test.py", line 7, in robjects.r('''source('r_code.R')''') File "/usr/local/lib/python2.7/dist-packages/rpy2/robjects/init.py", line 246, in call
res = self.eval(p) File "/usr/local/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 166, in call
return super(SignatureTranslatedFunction, self).call(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 99, in call
res = super(Function, self).call(*new_args, **new_kwargs) rpy2.rinterface.RRuntimeError: Error in readLines(file, warn = FALSE) :
5 arguments passed to .Internal(readLines) which requires 6
The funny thing is, it was working not so long ago and I haven't changed anything (at least I don't think I have) on my system.
Python version: 2.7.3
Numpy version: 1.8.0
Rpy2 version: 2.4.4
R version: 3.0.2
Ubuntu: 12.04.2
Any ideas? Thanks!