1

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!

Community
  • 1
  • 1
mongotop
  • 7,114
  • 14
  • 51
  • 76

1 Answers1

4

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.

David Robinson
  • 77,383
  • 16
  • 167
  • 187
  • it did!!! and it answer my question, and I will mark it as accepted!!! thanks a lot, can I ask you a another question indie please, what do I get c is not defined error? I'm just using as a vector as I read here http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/robustbase/html/adjboxStats.html – mongotop May 14 '13 at 20:15
  • `c` is an `R` function and it is not a Python function. Instead use `r.c`. – David Robinson May 14 '13 at 20:22
  • Hi David, thank you very much! I tried r.c and my code stop on executing, the execution wont finish and it hang and i have to kill the process every time I run the script, do you have any idea why this might be happening for? thank you very much again!! – mongotop May 15 '13 at 15:16
  • @mongotop Could you post this as a new question, including an entirely reproducible example? That is- it should have a snippet of Python code that, as long as someone runs that exact code and has rpy2 installed (and robustbase installed) it should give the same error? – David Robinson May 15 '13 at 15:26
  • @mongotop: Oh- it looks like you just did – David Robinson May 15 '13 at 15:27
  • yes :) here http://stackoverflow.com/questions/16569105/what-is-the-python-numpy-or-scipy-or-pandas-equivalent-for-rs-adjboxstats-fun for future. – mongotop May 15 '13 at 15:27
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30009/discussion-between-mongotop-and-david-robinson) – mongotop May 15 '13 at 15:27