Skip to content

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

3 messages · Romain Francois, Dirk Eddelbuettel

#
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)

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)

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.

... 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.

Romain
#
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
#
On 01/27/2010 04:01 AM, Dirk Eddelbuettel wrote:
Might be worth looking at how boost does it:
http://www.boost.org/doc/libs/1_41_0/doc/html/date_time.html

We can have both as<time_t> as as<Rcpp::Time> or whatever, where our 
class potentially deals with micro-second stuff.

I'm not rushed. Popped into my head yesterday while looking at your new 
unit tests.
Yes, we surely do. And this does not even have to be in Rcpp itself 
since it needs no modification of the class hierarchy. That could make a 
simple self-contained example of how to take advantage of Rcpp's api.