[Rcpp-devel] times, dates, etc .... in the new apis

Dirk Eddelbuettel edd at debian.org
Wed Jan 27 04:01:54 CET 2010


On 26 January 2010 at 20:25, Romain Francois wrote:
| What about something like :
| 
| class Rcpp::Date similar to RcppDate.
| 
| and :
| 
| as<Date>(SEXP)
| as<vector<Date>>(SEXP)
| wrap<Date>(const Date& date)
| wrap<vector<Date>>(const vector<Date>& date)

Yes. That is probably desirable. 

| and maybe perhaps also:
| 
| as<time_t>(SEXP)
| as<vector<time_t>>(SEXP)
| wrap<time_t>( const time_t& t)
| wrap<vector<time_t>>( const vector<time_t>& t)

That is trickier. 'time_t' stops at second resolution, POSIXct uses just one
double yet also managed microsecond granularity thanks to BDR. R is
non-standard here so it is tricky to mesh that with C++.  In some
applications I simply kept time as a fractional double at the C++ level and
simply casted it to POSIXct once at the R level.

TZ transitions and accidentally dropping TZ can be tiocky.
 
| We probably not need additional Rcpp:: classes (apart maybe from Date) 
| here, so that all the wrap versions above could return a NumericVector 
| but setting the attributes differently.

We might for Datetime. I'd say let's not rush this, we have other things we
know we have to knock off first.

| ... actually now that I think of it, for Date we should just have to 
| create:
| - operator SEXP()
| - Date(SEXP)
| 
| in order to get as and wrap for free (could be a good example for what 
| the NEWS pretends.

That would be elegant indeed.  And Date is 'just' an int relative to given offsets.  
 
Dirk

-- 
Three out of two people have difficulties with fractions.


More information about the Rcpp-devel mailing list