2016-08-09 4 views
0

パッケージrpy2を使用している間、以下のようにfile.pyが定義されているパイソン - rpy2との統合と「アトミックでなければなりません」というエラー

file.R_func.rdc([1,2,3,4,5],[1,3,4,5,6],20,1.67) 

実行するとき、私は

Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 86, in call return super(SignatureTranslatedFunction, self).call(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 35, in call res = super(Function, self).call(*new_args, **new_kwargs) rpy2.rinterface.RRuntimeError: Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic

エラーが表示されます。

from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage 

string = """ 
rdc <- function(x,y,k,s) { 
x <- cbind(apply(as.matrix(x),2,function(u) ecdf(u)(u)),1) 
y <- cbind(apply(as.matrix(y),2,function(u) ecdf(u)(u)),1) 
wx <- matrix(rnorm(ncol(x)*k,0,s),ncol(x),k) 
wy <- matrix(rnorm(ncol(y)*k,0,s),ncol(y),k) 
cancor(cbind(cos(x%*%wx),sin(x%*%wx)), cbind(cos(y%*%wy),sin(y%*%wy)))$cor[1] 
} 

""" 

R_func = SignatureTranslatedAnonymousPackage(string, "R_func") 

どのようにxとyをrdc()に渡す必要がありますか?

答えて

0

file.R_func.rdc([1,2,3,4,5],[1,3,4,5,6],20,1.67) 

Pythonオブジェクトの暗黙的な変換を行う基礎となるRの関数にパラメータとして渡す前に行われます。

デフォルトでは、(Pythonのlistある)[1,2,3,4,5]はR listに変換され、Rリストはリスト内の各要素は、「反対にすることにより、任意のオブジェクトとすることができることを意味する、「非アトミックベクター」であります等「(Rの専門用語で "論理)、整数、文字列、アトミック例えばbooleanとしてタイプ" ...

試行:

from rpy2.robjects.vectors import IntVector, FloatVector 
# FloatVector is imported as an alternative if you need/prefer floats 

file.R_func.rdc(IntVector([1,2,3,4,5]), 
       IntVector([1,3,4,5,6]), 
       20, 
       1.67) 
関連する問題