[Rcpp-devel] NA value for dates

Theodore Lytras thlytras at gmail.com
Fri Oct 5 22:55:15 CEST 2012


Στις Παρ 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".
[snip]
> 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")
a
[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??

Thank you again,

Theodore


More information about the Rcpp-devel mailing list