Simone Gabbriellini wrote:
> Dear List,
>
> sorry, but it's me again, because I still cannot figure out how to do
> this thing...
>
> I have my matrix in R as a numpy.array, everything is ok:
>
> In [35]: mymatrixR
> Out[35]: <RArray - Python:0x19c175a8 / R:0x1af39800>
>
> now I want to put mymatrixR inside the R object QAP, something like
>
> QAPset[,,1]<-mymatrixR
>
> if I simply do:
>
> robjects.r('QAP<-array(dim=c(50,50,2))')
>
> robjects.r('QAP[,,1]<-mymatrixR')
>
> Errore in eval(expr, envir, enclos) : oggetto "mymatrixR" non trovato
"mymatrixR" is a symbol in the "Python world", if you like. It does nto
make it a known symbol in the "R world".
If the earlier emails did not clarify this, look at how the variables
"weight" and "group" are assigned to globalEnv in an example:
http://rpy.sourceforge.net/rpy2/doc/html/introduction.html#linear-models
Your R will not know anything called "mymatrixR" until you assign an
object to that name, e.g.:
robjects.globalEnv['mymatrixR'] = mymatrixR
If you want to use anonymous variables, one way is to interpolate the
object as R code, as in:
http://rpy.sourceforge.net/rpy2/doc/html/introduction.html#interpolating-r-objects-into-r-code-strings
In your case that's.
rcode_str = 'QAP[, , 1] <- %s' %mymatrixR
robjects.r(rcode_str)
(and to anticipate a possible next question, you can retrieve QAP with
qap = robjects.globalEnv['QAP']
)
L.
> ---------------------------------------------------------------------------
> RRuntimeError Traceback (most recent call last)
>
> /Users/ogabbrie/Desktop/NetworkSimulatorTraits/<ipython console> in <module>()
>
> /Library/Frameworks/Python.framework/Versions/4.1.30101/lib/python2.5/site-packages/rpy2/robjects/__init__.pyc
> in __call__(self, string)
> 532 def __call__(self, string):
> 533 p = self.parse(text=string)
> --> 534 res = self.eval(p)
> 535 return res
> 536
>
> /Library/Frameworks/Python.framework/Versions/4.1.30101/lib/python2.5/site-packages/rpy2/robjects/__init__.pyc
> in __call__(self, *args, **kwargs)
> 420 for k, v in kwargs.iteritems():
> 421 new_kwargs[k] = conversion.py2ri(v)
> --> 422 res = super(RFunction, self).__call__(*new_args, **new_kwargs)
> 423 res = conversion.ri2py(res)
> 424 return res
>
> RRuntimeError: Errore in eval(expr, envir, enclos) : oggetto
> "mymatrixR" non trovato
>
> how should I refer to mymatrixR?
>
> thanks,
> simone
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> rpy-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list