Re: [Rd] sapply improvements

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Thu, 05 Nov 2009 17:30:02 +0100

>>>>> Duncan Murdoch <murdoch_at_stats.uwo.ca> >>>>> on Thu, 05 Nov 2009 06:24:24 -0500 writes:

    > On 05/11/2009 4:05 AM, Martin Maechler wrote:
    >>>>>>> "PD" == Peter Dalgaard <p.dalgaard_at_biostat.ku.dk> on
    >>>>>>> Thu, 05 Nov 2009 00:28:51 +0100 writes:

>>

    PD> William Dunlap wrote: ...
>> >>>
>> >>> if (x <= 0) NA else log(x)
>> >>>
>> >>> variety otherwise.
>> >>
>> >> Would you only want it to coerce upwards to
>> FUN.VALUES's >> type? E.g., allow sapply(z, length, >>
>> FUN.VALUE=numeric(1)) to return a numeric vector but die
>> >> on sapply(z, function(zi)as.complex(zi[1]), >>
>> FUN.VALUE=numeric(1)) If the latter doesn't die should it
>> >> return a complex or a numeric vector? (I'd say it
>> needs >> to be numeric, but I'd prefer that it died.)
>>
    PD> I'd say that it should probably die on downwards
    PD> coercion. Getting a double when an integer is expected,
    PD> or complex instead of double as you indicate, is a
    PD> likely user error. If not, then the user can always
    PD> coerce explicitly inside FUN.

>>
>> I agree with Peter: Do allow coercion downwards
    > You missed "not", right?  I.e. we would never coerce a
    > double down to an integer or logical, but coercion in the
    > other direction would be fine?

Yes, indeed. I missed and you are right. Martin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 05 Nov 2009 - 16:32:56 GMT

This archive was generated by hypermail 2.2.0 : Thu 05 Nov 2009 - 17:00:23 GMT