On 2011-11-28 14:07, Luca Beltrame wrote:
In data sabato 26 novembre 2011 06:53:48, Laurent Gautier ha scritto:
Currently, the constructor to DataFrame accepts a "tlist" ("tagged
list") as a main parameter. The idea was to be relying on duck-typing,
Currently in fact I've been hitting some walls regarding that. I assume that
the low-level interface should be used to reduce overhead.
Yes it should, if the overhead matters.
The robjects layer is slower, but it is only of relevance in some cases
(http://rpy.sourceforge.net/rpy2/doc-2.3/html/performances.html#a-simple-benchmark
yes, in that example rpy2's low-level interface can be 7 times faster
than R itself ;-) )
Currently setting a
matrix by tlist will fail because the type is not VECSXP, but rather of the
type that it was generated from (eg. ints if it was created by an IntVector).
So that brings the first question: how can I reliably detect that "tlist" is a
Matrix? I thought about using isinstance() but I'm not sure if that would
introduce overhead.
Every function call introduces an overhead (no hints for the compiler
such a C's "inline" here); the question is: does it matter ?
"isinstance()" would be a good way to check it in Python.
I noticed that the code tries to create key, value pairs in tuples which then
are sent to rcall() to create the object: in the specific case of Matrix, this
messes up the column order (rows become columns).
To be precise, the code I *tried* to use:
kv = [(k, v) for k, v in tlist.iteritems()]
kv = tuple(kv)
df = baseenv_ri.get("data.frame").rcall(kv, globalenv_ri)
super(DataFrame, self).__init__(df)
which doesn't really work (creates rows as columns).
What about something along the lines of:
base = importr('base')
def as_dataframe(m):
assert(isinstance(m, Matrix))
# since we did test that this is a Matrix
# we may as well skip R's dispatch system
res = base.as_data_frame_matrix(m)
return res
?
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list