[Rcpp-devel] NA value for dates
edd at debian.org
Fri Oct 5 23:12:14 CEST 2012
On 5 October 2012 at 23:55, Theodore Lytras wrote:
| Στις Παρ 05 Οκτ 2012, ο/η Dirk Eddelbuettel έγραψε:
| > On 5 October 2012 at 21:39, Theodore Lytras wrote:
| > | Hello all,
| > |
| > | I am trying to pass from C++ to R a DateVector with a few missing items
| > | (NAs). I can't seem to find a way, though.
| > | There does not seem to be a NA_DATE (like NA_REAL, etc), and the default
| > | constructor for Rcpp::Date creates a date of "-5877641-06-23".
| > I've never tried this, but as Dates in R really are just integers since the
| > epoch -- so maybe the NA_INTEGER aka R_NaInt will work?
| I tried this already - it doesn't.
| Neither do the other constants (NA_REAL and NA_LOGICAL).
| I also tried Rcpp::Date(NA_INTEGER).
| They all create a date of "-5877641-06-23".
| > At a more conceptual level, NA shouldn't really be in dates, right? Either
| > is a valid date, or it is missing (NULL). There simply is no such thing as
| > Feb 30 or April 31.
| Not really, because NA is the natural choice to indicate a missing value. If
| for example one has a vector with 10 date observations and wants to indicate
| that the 3rd is missing, one has to use NA. With NULL one gets a vector of
| size 9. NA is necessary to have for all data types.
| And it is supported in the R interpreter, for example:
| a <- as.Date(c(3883, NA, 15120), origin="1970-1-1")
|  "1980-08-19" NA "2011-05-26"
| 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:
 "1970-01-02" "1970-01-03" NA "1972-02-17"
maybe Rcpp should too. But you're the one with the itch to scratch... so
help would be appreciated.
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel