From ggrothendieck at gmail.com  Fri Mar 18 15:25:42 2016
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 18 Mar 2016 10:25:42 -0400
Subject: [Rd] for in r-devel
Message-ID: <CAP01uRmNXTg1Qb+8j5vMi2akOqRCQ4Yz6Gt_r=Q3=CHCDdVNWQ@mail.gmail.com>

Regarding, this news item for r-devel:

?for()? loops are generalized to iterate over any object with ?[[? and
?length()? methods. Thanks to Herv? Pag?s for the idea and the patch.

Below dd is an object for which [[ and length work but the result is
still numeric rather than Date class in  "R Under development
(unstable) (2016-03-15 r70334)" as observed in the comments to:
http://stackoverflow.com/questions/36074344/why-does-for-convert-date-to-numeric#comment59794873_36074344
Expanding on that:

    dd <- Sys.Date() + 0:1

    dd[[1]]  # [[ works
    ## [1] "2016-03-18"

    length(dd)  # length works
    ## [1]  2

    for(d in dd) str(d)  # gives numeric rather than Date class
    ## num 16878
    ## num 16879


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



[Rd] for in r-devel
Gabor Grothendieck