I'm using R to do some data manipulation. This is a part of a larger project that is mostly in Python, so I'm not using R directly but RPy2 instead. Things work fine until I get to the dplyr part.
This 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)
That gives me the data I want.
But when I try to do some data manipulation with dplyr, like this:
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 get an 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've tried escaping the % signs, escaping the > sign, and putting them within quotation marks, but nothing worked.
What am I missing?
I've seen the other questions about the same error (like here and here) but they didn't help.
I'm using Python 2.7.10 and RPy2 2.5.6.