[Rcpp-devel] NA value for dates

Theodore Lytras thlytras at gmail.com
Sat Oct 6 09:15:52 CEST 2012


Στις Σαβ 06 Οκτ 2012, ο/η Dirk Eddelbuettel έγραψε:
> | Shouldn't there be a special value (like R_NaInt) or a special object or
> | something, that represents NA dates??
> 
> Maybe. Feel like working on a patch?  src/RcppDate.cpp is pretty
> straightforward and mostly free of template magic.  It may just need a
> layer of NA testing I didn't add when I wrote that.
> 
> I am with you as R can do this:
> 
> R> as.Date(c(1,2,NA,777))
> [1] "1970-01-02" "1970-01-03" NA           "1972-02-17"
> R>
> 
> maybe Rcpp should too.  But you're the one with the itch to scratch... so
> help would be appreciated.
> 
> Dirk

I would LOVE to offer assistance, but I don't think I can do much - my C/C++ 
knowledge is fairly limited.

I checked out Rcpp's src/Date.cpp . It seems all the work is done on 
Date::update_tm(), which calls gmtime_(). But where is struct tm and time_t 
defined? I guess this is the internal representation of dates in R, correct?

I tried peeking inside a (gunzipped) .RData file to find out how NA is stored. 
It seems that both with numeric vectors and with date vectors it is stored 
with the same 8 bytes: 7F F8 00 00 00 00 07 A2, which I believe is the value 
if R_NaReal. I don't know if that helps, but I guess that struct tm probably 
contains a double rather than an integer, which should be set to this value.

So if you would please give me some hints, I would do my best to help.

Theodore


More information about the Rcpp-devel mailing list