From josh.m.ulrich at gmail.com  Wed Aug 12 18:06:42 2015
From: josh.m.ulrich at gmail.com (Joshua Ulrich)
Date: Wed, 12 Aug 2015 11:06:42 -0500
Subject: [Rd] Weird issue when iterating through dates
In-Reply-To: <CABtg=K=qGcsg_tH7m=c0KEzc1mdqMM3ETjB4JNQeOMnS4ehNdg@mail.gmail.com>
References: <CAFnz2--pK12My=sJ-N0sykXi0zQa+qwtR42iZo2fBrpiTTWOCg@mail.gmail.com>
	<CABtg=K=b5Amh17=9wZ=g2j9F63KtYEYSDWoQEOGx7kvYEdBHZA@mail.gmail.com>
	<CAFnz2-8902ztc-=gcwcA4jnYHkX9PL0oNMctGjtmXdynQjYRcg@mail.gmail.com>
	<CABtg=K=PB+r1FHuzcK1pGMXQFo=peuTGWx_CL_CczkspwXq3SA@mail.gmail.com>
	<CAF8bMcYHLfxVaT-NT1SiOTzrBEGM6vgr+PwwzGQGAJ6kGZx_MA@mail.gmail.com>
	<CAFnz2-9z0R6xf_RzmtFrHcQKCVbip+jEH+E1+Uj2MuCoerXbMg@mail.gmail.com>
	<CABtg=K=qGcsg_tH7m=c0KEzc1mdqMM3ETjB4JNQeOMnS4ehNdg@mail.gmail.com>
Message-ID: <CAPPM_gRzPpRCxDtvPNdS-VFgvb_DViKksNVHw62u1Gg+zBSH8A@mail.gmail.com>

On Wed, Aug 12, 2015 at 10:55 AM, G?bor Cs?rdi <csardi.gabor at gmail.com> wrote:
> I am not sure if this is a bug or not.
>
I would argue that this isn't a bug, not even in the documentation of
"for" (even though it might be clearer).  ?"for" says that `seq` is
"[A]n expression evaluating to a vector (including a list and an
expression) or to a pairlist or 'NULL'".  Date objects aren't strictly
vectors, so they're treated as integer/numeric.

This answer on StackOverflow said that "for" does not copy any of the
iterators attributes (including class), which causes this behavior.
http://stackoverflow.com/a/23278464/271616

To respond to the original question regarding why the code below,
"prints the dates as a string".  Quite simply, you convert seq(d1,d2,
by=1) to character, so it's no longer a Date.  The fact that
Sys.Date() and as.character(Sys.Date()) both *print* the same thing
does not mean they are the same.

for ( dt in as.character(seq(d1,d2, by=1)) ) {
  print(dt)
}

Best,
Josh

> Gabor
>
> On Wed, Aug 12, 2015 at 11:51 AM, Luca Cerone <luca.cerone at gmail.com> wrote:
>> Following up on this, should I report a bug? can you drive me through
>> the process?
>>
>> Cheers,
>> Luca
>>
>> On Thu, Aug 6, 2015 at 4:55 PM, William Dunlap <wdunlap at tibco.com> wrote:
>>>>> Just a quick question: what's the difference between  `[.Date` and
>>>>> `[[.Date`?
>>>>> Is it supposed to be the method for accessing the value right?
>>>>
>>>>For Dates and atomic vectors in general they are the same, but ...
>>>
>>> Even for atomic vectors with names they are not quite the same
>>>     > c(One=1, Two=2)[[2]]
>>>     [1] 2
>>>     > c(One=1, Two=2)[2]
>>>     Two
>>>       2
>>> (and [[ will only return 1 item, unlike [).
>>>
>>>
>>> Bill Dunlap
>>> TIBCO Software
>>> wdunlap tibco.com
>>>
>>> On Thu, Aug 6, 2015 at 5:36 AM, G?bor Cs?rdi <csardi.gabor at gmail.com> wrote:
>>>>
>>>> On Thu, Aug 6, 2015 at 6:30 AM, Luca Cerone <luca.cerone at gmail.com> wrote:
>>>> [...]
>>>> > Just a quick question: what's the difference between  `[.Date` and
>>>> > `[[.Date`?
>>>> > Is it supposed to be the method for accessing the value right?
>>>>
>>>> For Dates and atomic vectors in general they are the same, but in
>>>> general they are two different operators that behave differently on
>>>> some data types. E.g. on lists [ selects a sub-list and [[ selects a
>>>> single element.
>>>>
>>>> Gabor
>>>>
>>>> [...]
>>>>
>>>> ______________________________________________
>>>> R-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



[Rd] Weird issue when iterating through dates
Joshua Ulrich