[R] strange date problem - May 3, 1992 is NA

Brian Diggs diggsb at ohsu.edu
Wed Jun 22 22:46:02 CEST 2011


On 6/22/2011 1:23 PM, William Dunlap wrote:
> The isdst value -1 doesn't seem right.  Shouldn't it
> be either 0 (not daylight savings time) or 1 (yes dst)?
> I've only seen isdst==-1 when all the other entries
> were NA (that happens when the string doesn't match
> the format).

A isdst of -1 indicates that the dst status of that time is not known. 
I've seen (and submitted patches to use) this when internally mucking 
with the parts of a POSIXlt.  Changing, say, the hour of a valid POSIXlt 
value may result in a configuration which is not consistent (crossed a 
DST boundary).  This POSIXlt behaves fairly well, but when converted to 
a POSIXct, gives NA.  These conversions often happen behind the scenes. 
  In particular:

 > is.na.POSIXlt
function (x)
is.na(as.POSIXct(x))
<environment: namespace:base>

It may be that as.POSIXct.POSIXlt can handle isdst==-1 when the DST 
status is unambiguous, but maybe not when it is.  I'm curious what the 
specifics of the timezone Alexander is working in.

> In the parts of the US where daylight savings time is
> used the switchover took place near the beginning of
> April in 1992, so you should have isdst=1 by May 3.
> Perhaps you have an odd timezone file on your machine.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -----Original Message-----
>> From: Alexander Shenkin [mailto:ashenkin at ufl.edu]
>> Sent: Wednesday, June 22, 2011 1:07 PM
>> To: William Dunlap
>> Subject: Re: [R] strange date problem - May 3, 1992 is NA
>>
>> Hi Bill,
>>
>> Thanks for your reply.  The results look almost identical to my eyes,
>> except for the mysterious "TRUE"...
>>
>>> methods("is.na")
>> [1] is.na.data.frame      is.na.numeric_version is.na.POSIXlt
>>> trace(methods("is.na"), quote(cat(" is.na: class(x)=",
>> class(x), "\n")))
>> Tracing function "is.na.data.frame" in package "base"
>> Tracing function "is.na.numeric_version" in package "base"
>> Tracing function "is.na.POSIXlt" in package "base"
>> [1] "is.na.data.frame"      "is.na.numeric_version" "is.na.POSIXlt"
>>> z<- strptime("5/3/1992", format="%m/%d/%Y")
>>> is.na(z)
>> Tracing is.na.POSIXlt(z) on entry
>>   is.na: class(x)= POSIXlt POSIXt
>> [1] TRUE
>>> str(unclass(z))
>> List of 9
>>   $ sec  : num 0
>>   $ min  : int 0
>>   $ hour : int 0
>>   $ mday : int 3
>>   $ mon  : int 4
>>   $ year : int 92
>>   $ wday : int 0
>>   $ yday : int 123
>>   $ isdst: int -1
>>
>>
>>> sessionInfo()
>> R version 2.12.1 (2010-12-16)
>> Platform: i386-pc-mingw32/i386 (32-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252
>> [2] LC_CTYPE=English_United States.1252
>> [3] LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.12.1
>>
>> thanks,
>> allie
>>
>> On 6/22/2011 1:50 PM, William Dunlap wrote:
>>> What do you get for the following commands, which
>>> show which is.na method is getting called and
>>> the internal structure of the dataset made
>>> by strptime?
>>>
>>>> methods("is.na")
>>> [1] is.na.data.frame      is.na.numeric_version is.na.POSIXlt
>>>> trace(methods("is.na"), quote(cat(" is.na: class(x)=", class(x),
>>> "\n")))
>>> Tracing function "is.na.data.frame" in package "base"
>>> Tracing function "is.na.numeric_version" in package "base"
>>> Tracing function "is.na.POSIXlt" in package "base"
>>> [1] "is.na.data.frame"      "is.na.numeric_version" "is.na.POSIXlt"
>>>> z<- strptime("5/3/1992", format="%m/%d/%Y")
>>>> is.na(z)
>>> Tracing is.na.POSIXlt(z) on entry
>>>   is.na: class(x)= POSIXlt POSIXt
>>> [1] FALSE
>>>> str(unclass(z))
>>> List of 9
>>>   $ sec  : num 0
>>>   $ min  : int 0
>>>   $ hour : int 0
>>>   $ mday : int 3
>>>   $ mon  : int 4
>>>   $ year : int 92
>>>   $ wday : int 0
>>>   $ yday : int 123
>>>   $ isdst: int 1
>>>
>>>
>>>
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com
>>>
>>>> -----Original Message-----
>>>> From: r-help-bounces at r-project.org
>>>> [mailto:r-help-bounces at r-project.org] On Behalf Of
>> Alexander Shenkin
>>>> Sent: Wednesday, June 22, 2011 11:41 AM
>>>> To: Sarah Goslee; r-help at r-project.org
>>>> Subject: Re: [R] strange date problem - May 3, 1992 is NA
>>>>
>>>> On 6/22/2011 1:34 PM, Sarah Goslee wrote:
>>>>> On Wed, Jun 22, 2011 at 2:28 PM, David Winsemius
>>>> <dwinsemius at comcast.net>  wrote:
>>>>>>
>>>>>> On Jun 22, 2011, at 2:03 PM, Sarah Goslee wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> On Wed, Jun 22, 2011 at 11:40 AM, Alexander Shenkin
>>>> <ashenkin at ufl.edu>
>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
>>>>>>>>
>>>>>>>> [1] FALSE
>>>>>>>>>
>>>>>>>>> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
>>>>>>>>
>>>>>>>> [1] TRUE
>>>>>>>
>>>>>>> I can't reproduce your problem on R 2.13.0 on linux:
>>>>>>
>>>>>> I also cannot reproduce it on a Mac with 2.13.0 beta
>>>>>
>>>>> Which strongly suggests that you should start by upgrading your R
>>>>> installation if at all possible.
>>>>>
>>>>> I'd also recommend trying it on a default R session, with no extra
>>>>> packages loaded, and no items in your workspace. It's
>> possible that
>>>>> something else is interfering.
>>>>>
>>>>> On linux, that's achieved by typing R --vanilla at the
>> command line.
>>>>> I'm afraid I don't know how to do it for Windows, but should be
>>>>> similarly straightforward.
>>>>>
>>>> Thanks Sarah.  Still getting the problem.  I should surely
>>>> upgrade, but
>>>> still, not a bad idea to get to the bottom of this, or at
>>>> least have it
>>>> documented as a known issue.  BTW, I'm on Windows 7 Pro x64.
>>>>
>>>> (running Rgui.exe --vanilla):
>>>>
>>>>> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
>>>> [1] TRUE
>>>>
>>>>> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
>>>> [1] FALSE
>>>>
>>>>> sessionInfo()
>>>> R version 2.12.1 (2010-12-16)
>>>> Platform: i386-pc-mingw32/i386 (32-bit)
>>>>
>>>> locale:
>>>> [1] LC_COLLATE=English_United States.1252
>>>> [2] LC_CTYPE=English_United States.1252
>>>> [3] LC_MONETARY=English_United States.1252
>>>> [4] LC_NUMERIC=C
>>>> [5] LC_TIME=English_United States.1252
>>>>
>>>> attached base packages:
>>>> [1] stats     graphics  grDevices utils     datasets
>> methods   base
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>
>


-- 
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University



More information about the R-help mailing list