[Rcpp-devel] times, dates, etc .... in the new apis
francoisromain at free.fr
Wed Jan 27 08:14:22 CET 2010
On 01/27/2010 04:01 AM, Dirk Eddelbuettel wrote:
> 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.
Might be worth looking at how boost does it:
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
> | 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.
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.
> | ... 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.
Professional R Enthusiast
+33(0) 6 28 91 30 30
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009
More information about the Rcpp-devel