"Error while parsing string" when using RPy2 and dplyr

I am using R to process data. This is part of a larger project that mostly runs in Python, so I don't use R directly, but RPy2. Everything works fine until I get to the dplyr part.

It works:

from rpy2.robjects import r

Rcode = '''library(RODBC)
library(dplyr)
# ...
# a bunch of R code that fetches data from SQL Server
# ...'''.format(db_name = 'foo')
print r(Rcode)

      

This gives me the data I want.

But when I try to manipulate data with dplyr like:

from rpy2.robjects import r

Rcode = '''library(RODBC)
library(dplyr)
# ...
# a bunch of R code that fetches data from SQL Server
# ...
myData <- myData
    %>% group_by(someDataField)'''.format(db_name = 'foo')
print r(Rcode)

      

I am getting the error:

Traceback (most recent call last):
  File "myScript.py", line 53, in <module>
    print r(Rcode)
  File "C:\Python27\lib\site-packages\rpy2\robjects\__init__.py", line 268, in __call__
    p = rinterface.parse(string)
ValueError: Error while parsing the string.

      

I tried to get out of the% sign, get out of the> sign and put them in quotes, but nothing worked.

What am I missing?

I've seen other questions about the same error (like here and here ) but they didn't help.

I am using Python 2.7.10 and RPy2 2.5.6.

+3


source to share


1 answer


myData <- group_by(MyData,someDataField)

      



+1


source







All Articles