Re: [Rd] sapply(Date, is.numeric) (PR#12239)

From: <maechler_at_stat.math.ethz.ch>
Date: Thu, 07 Aug 2008 12:04:53 +0200 (CEST)


>>>>> "RobMcG" == McGehee, Robert <Robert.McGehee_at_geodecapital.com> >>>>> on Tue, 29 Jul 2008 15:40:37 -0400 writes:

    RobMcG> FYI,
    RobMcG> I've tried posting the below message twice to the bug tracking system,

    [....... r-bugs problems discussed in a separate thread ....]

    RobMcG> R-developers,
    RobMcG> The results below are inconsistent. From the documentation for
    RobMcG> is.numeric, I expect FALSE in both cases.

>> x <- data.frame(dt=Sys.Date())
>> is.numeric(x$dt)
    RobMcG> [1] FALSE
>> sapply(x, is.numeric)
    RobMcG> dt
    RobMcG> TRUE

    RobMcG> ## Yet, sapply seems aware of the Date class
>> sapply(x, class)
    RobMcG> dt
    RobMcG> "Date"

Yes, thanks a lot, Robert, for the report.

That *is* a bug somewhere in the .Internal(lapply(...)) C code, when S3 dispatch of primitive functions should happen.

Here's an R scriptlet exposing a 2nd example

### lapply(list, FUN)
### ------------------ seems to sometimes fail for
### .Primitive S3-generic functions

(ds <- seq(from=Sys.Date(), by=1, length=4)) ##[1] "2008-07-30" "2008-07-31" "2008-08-01" "2008-08-02" ll <- list(d=ds)
lapply(list(d=ds), round)
## -> Error in lapply(list(d = ds), round) : dispatch error

## or -- related to bug report by Robert McGehee on R-devel, on 2008-07-29: sapply(list(d=ds), is.numeric)
## TRUE ## in spite of
is.numeric(`[[`(ll,1)) ## FALSE , because of is.numeric.date

## or
round(`[[`(ll,1))
## [1] "2008-07-30" "2008-07-31" "2008-08-01" "2008-08-02"

##-----------------------------

But I'm currently too much tied up with other duties, to find and test bug-fix.

Martin Maechler, ETH Zurich and R-Core Team



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 07 Aug 2008 - 10:31:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Aug 2008 - 10:36:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive