On Thu, Feb 24, 2011 at 07:57:19AM +0100, Laurent wrote:
> On 24/02/11 00:12, Artur Wroblewski wrote:
> >On Wed, Feb 23, 2011 at 8:00 PM, Laurent Gautier<lgaut...@gmail.com>  wrote:
> >[...]
> >>Rpy2 aims at doing very little hidden magic or second guessing of the user's
> >>intention (R is already enough).
> >
> >Probably "magic" is bad word.
> >
> >>I have considered the option of having an "on_fail" (or other name)
> >>parameter to specify a value to use is conversion to the required type
> >>fails, but chose to keep the interface simple unless need.
> >
> >What I would expect from rpy in case of FloatVector (or other vector)
> >- accept any Python iterable as argument (not only lists and sequences)
> 
> I considered that but there was no performance gain from doing so so
> left it out: to create an R vector the length must be known from the
> beginning, and the iterator must be unwind into a sequence before
> anything else.
> Thinking further what can be added is a test to rescue non-sequences
> that happen to be iterables and internally unwind them into a tuple.

It is less about performance but more about convenience. Every Python
container (tuple, list, set, dict) and related functions (zip) accept
iterables at the moment. Unwinding is OK for me in such case.

Also, some iterable might implement __len__ operator, but not being tuple
or list.

> >- accept anything what Python's "float" function accepts, which is string,
> >  integer and float as item of above iterable, i.e. (1, "1", 1.0)
> >  shall be accepted
> 
> I'd prefer sticking to what array.array accepts since it is
> conceptually closer.
> (Long) experience tells that those seemingly convenience functions
> are bug nests.
> 
> You can still tweak it the way you prefer by subclassing the
> existing classes, and you also have R's as.numeric().
> import rpy2.interactive as r
> my_iterable = (x for x in (1, "1", 1.0))
> r.packages.base.as_numeric(*tuple(my_iterable))

OK.

> >- by default, convert Python's None to R's NA; add optional vector 
> >constructor
> >   parameter to allow conversion of None to R's NULL (or maybe even
> >   other value), i.e. FloatVector(iterable, none=R.NA)
> 
> I am somewhat reluctant. Python's None is closer to R's NULL. The
> multiple parameter thing seems like complication that would not
> benefit the greatest number.

In Python

    >>> (1, None, 2, None, 3)
    (1, None, 2, None, 3)

In R

    > c(1, NULL, 2, NULL, 3)
    [1] 1 2 3                 <- NULL is removed, by default

    > c(1, NA, 2, NA, 3)
    [1]  1 NA  2 NA  3        <- NA is kept, by default

Above is problematic with data frames (vectors need to be the same length)

    a = [1, None, 2]
    b = range(3)     # in Python 3 this is iterable implementing __len__

    df = ro.DataFrame({
        'a': ro.FloatVector(a),
        'b': ro.FloatVector(tuple(b)),
    })


Best regards,

w

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to