[Rcpp-devel] NA value for dates
Dirk Eddelbuettel
edd at debian.org
Sat Oct 6 16:21:18 CEST 2012
Hi Theodore,
On 6 October 2012 at 10:15, Theodore Lytras wrote:
| I would LOVE to offer assistance, but I don't think I can do much - my C/C++
| knowledge is fairly limited.
We all said that at one point. Learning is about getting further, one step at
a time.
| 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?
Correctly spotted. Here 'struct tm' and 'time_t' are stand C library
structure and functions which R uses. [ R is picky and brings its replacement
gmtime and mktime to be more stable cross-platform, these would be standard
library else too. ]
It may be enough to just for NA when these are called, and if so, to not call
but pass NA. The system libraries do not know R's NA for Int (they only have
float NA) and hence return the crazy dates you saw.
| 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.
You are doing really good. These bit patterns are defined in the R headers,
we don't need them.
| So if you would please give me some hints, I would do my best to help.
Keep going. Keep sending email. I have some errands to do but will be around
email frequently enough.
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list