-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Laurent Gautier ha scritto:
> Anne Ghisla wrote:
>> Hi list,
>>
>> I'm using packaged rpy2 on Debian Squeeze in a python-grass script to
>> perform kriging and, among other things that rpy2 executes smoothly, I
>> need tho change the names of two columns in a dataframe.
>> This edit is necessary because the dataframe coming from previous
>> as.data.frame command receives arbitrary column names.
[cut]
> 
> One of the shortcomings in rpy2.robjects v2.0.x concerns the rebinding
> of underlying R objects, needed by the pass-by-value paradigm in R
> (rnumpy has been working around that by using delegation rather than
> inheritance). It has been fixed in rpy2-2.1dev.
> 
> Otherwise, since you want to replace the elements in a vector, the usual
> __setitem__ should replace them "in-place".
> 
> 
> suggestion:
> 
> new_names = robjects.r.gsub('letter','code',dataf.names)
> for i, val in enumerate(new_names):
> dataf.names[i] = val

Thanks for quick response! That's the ready-to-use rpy2 solution.
Actually, the mess is caused by my inexperience in handling sp objects,
to add coordinates as x-y columns in the data slot, so another
straightforward solution is to add x and y columns using GRASS commands.

> link:
> 
> http://rpy.sourceforge.net/rpy2/doc-dev/html/robjects.html#names

Great reading, thanks! Upgrading to 2.1-dev sounds tempting.

best regards,
Anne
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkpt39MACgkQrgxAvFOwDdj+BgCeOiDhOSsJFk2Ru2lSKpGtqjeW
m/oAnAruWt51rOdPkqONOyoEr5lI4OF+
=faZu
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to