Runing R code on `python` with SyntaxError: keyword can't be an expression error Message

北战南征 提交于 2019-12-11 11:58:58

问题


I'm looking to run some R code on python

I already installed the R package robustbase on ubunto using apt-get install r-cran-robustbase and rpy packege as well.

from the python console I can successfully run from rpy import * and r.library("robustbase") but when I run

result = robjects.FloatVector([11232.1, 234.2, 3445532344.3, 34302.3, 203.9, 232223.3, 3434.55])
print(result.r_repr())
r(adjboxStats(c(11232.1, 234.2, 3445532344.3, 34302.3, 203.9, 232223.3, 3434.55), coef = 2.5, a = -4, b = 3, do_conf = TRUE, do_out = TRUE))

to get the outliers values

But I get this error :

adjboxStats(c(11232.1, 234.2, 3445532344.3, 34302.3, 203.9, 232223.3, 3434.55), coef = 2.5, a = -4, b = 3, do.conf = TRUE, do.out = TRUE)
SyntaxError: keyword can't be an expression

when I run this on R console it works!!!

library("robustbase")
adjboxStats(c(11232.1, 234.2, 3445532344.3, 34302.3, 203.9, 232223.3, 3434.55), coef = 2.5, a = -4, b = 3, do.conf = TRUE, do.out = TRUE)

I search here , here and here but no luck. doesn anyone knows what is that error message for and is there's a way to go arround it?

Thanks!


回答1:


You can't use do.conf or do.out as arguments to a Python function (even if the function will be converted to R).

Instead, call them do_conf and do_out. You were then getting tripped up by another error, which is how you refer to r("adjboxStats"):

r("adjboxStats")(result, coef = 2.5, a = -4, b = 3, do_conf = True, do_out = True)

This will fix the syntax issues.



来源:https://stackoverflow.com/questions/16551373/runing-r-code-on-python-with-syntaxerror-keyword-cant-be-an-expression-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!