I am getting SyntaxError: keyword can't be an expression in a script I am working on.
I am using rpy2 (and the R package geoR) in Python to work with a data table that is retrieved from a PostgreSQL database using R's database functions. The data is spatial data with coordinates and 2 columns of numerical data that will be used in a geostatistical model.
After the database query call, the dataframe object x looks like this:
easting northing location attrib1 attrib2 category
1 658394.3 204987.5 p1 4.91 26.17 soil
2 658657.1 205116.7 p2 4.85 27.43 soil
...
I create an object for the geoR functions like this:
from rpy2.robjects.packages import importr geo = importr('geoR')
Calling the geoR function as
y=geo.as_geodata(x)
works, BUT without argument data.col, it assigns the location attribute as the data attribute. (First column after coordinate attributes is default.)
Trying:
y=geo.as_geodata(x,geo.data_col="4:5")
produces:
SyntaxError: keyword can't be an expression
I can't seem to get around it. I have looked at a few posts here and looked around online, but I can't figure this one out.
I think the error is due to you trying to pass two columns to the
data_colcommand. Here is a working example using themeusedataset from thegstatpackage.However you will notice that the above doesn't work, because
geoRdoesn't seem to get thecoords.color thedata.colarguments. I'm not sure why this is, but a workaround to this problem is to write a wrapping function.Using the above method you can pass additional arguments to the
as.geodatafunction within thegeodata_pythonfunction within theRenvironment.HTH