On 2011-09-12 21:16, Artur Wroblewski wrote:
> On Mon, Sep 12, 2011 at 12:26 PM, Laurent Gautier<[email protected]> wrote:
>> Probably not.
>>
>> R is doing a lot of things behind the hood. Sometimes it is good, sometimes
>> it is bad.
>> The code snippet given to you has a quadratic time-complexity ( O(nm) ). It
>> can be make linearithmic ( O(n log(m) ) ) simply:
>>
>> from rpy2.robjects.vector import BoolVector
>> ref = set(differential)
>> select_b = BoolVector(tuple(x in ref for x in source.rx2('gene')))
>> mysubset = source.rx(select_b, True)
> If I reckon well BoolVector(...genexpr...) is not possible here due to
> R API limitation - we need length of iterable, isn't it?
You might have missed the call to tuple(). This will make it work
independently of having a generator with a length.
>>> tuple(x for x in [1,2,3])
(1, 2, 3)
> It seems like copying R on Python level is not always nice
> and can be quite inefficient.
>
> Above probably could be rewritten in more Pythonic way (it would
> be more efficient I believe, as well)
>
> mysubset = source.rx((x in ref for x in source.rx2('gene')), True)
>
> or
>
> mysubset = DataFrame(row for row in source if row['gene'] in ref)
>
> but of course is not supported by rpy2.
>
> Is there a chance to make rpy2 bit more Python integrated? :)
As Luca wrote it earlier, what is missing for it to work is that the
generator had a length.
This can probably be addressed by adding a custom iterator for R
vectors, and should I appear a little slow to have it implemented you
are welcome to submit a patch. ;-)
Best,
L.
> Best regards,
>
> w
>
> ------------------------------------------------------------------------------
> Doing More with Less: The Next Generation Virtual Desktop
> What are the key obstacles that have prevented many mid-market businesses
> from deploying virtual desktops? How do next-generation virtual desktops
> provide companies an easier-to-deploy, easier-to-manage and more affordable
> virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
> _______________________________________________
> rpy-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rpy-list
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry® mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry® DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list