On 21/07/2010 18:27, Laurent wrote:
On 21/07/10 16:54, rey sebastien wrote:
Hello guys,
I'm having some trouble to understand the mapping with rpy2 object and
python object.
I have a function(x) which return a tuple object in python, and i want
to map this tuple object with R object list or vector.
_
First, i'm trying to do this : _
robjects.r.tlist = get_max_ticks(x) # return a tuple into this object
tlist
#Convert list into dataframe
r('x <- as.data.frame(tlist,row.names=c("seed","ticks"))')
FAIL with error :
rinterface.RRuntimeError: Error in eval(expr, envir, enclos) : object
'tlist' not found
_
So i'm trying an other strategy : _
robjects.r["tlist"] = get_max_ticks(x)
r('x <- as.data.frame(tlist,row.names=c("seed","ticks"))')
FAIL with this error :
TypeError: 'R' object does not support item assignment
Could you help me to understand ?
What about starting with the documentation ?
http://rpy.sourceforge.net/rpy2/doc-2.1/html/robjects.html#creating-objects
Thx but i have already read a part of the official documentation, but it
seems this paragraph don't resolve my problem :/
A guys on stackoverflow resolve my problem, and explain this :*
import rpy2.robjects as ro
r=ro.r
def get_max_ticks():
return (1,2)
ro.globalEnv['tlist'] = ro.FloatVector(get_max_ticks())
r('x <- as.data.frame(tlist,row.names=c("seed","ticks"))')
print(r['x'])
# tlist
# seed 1
# ticks 2
It may be possible to access symbols in the R namespace with this type
of notation: robjects.r.tlist, but you can not assign values this way.
The way to assign symbol is to use robject.globalEnv.
Moreover, some symbols in R may contain a period, such as data.frame.
You can not access such symbols in Python using notation similar to
robjects.r.data.frame, since Python interprets the period differently
than R. So I'd suggest avoiding this notation entirely, and instead use
robjects.r['data.frame'], since this notation works no matter what the
symbol name is.*
the link for answer :
http://stackoverflow.com/questions/3300671/mapping-python-tuple-and-r-list-with-rpy2
Thx a lot!
S.Rey
Thanks a lot !!
------
S.Rey
Phd @ "geographie-cités" Paris
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list