[Rcpp-devel] Problem with Rcpp::Datetime

Dominick Samperi djsamperi at gmail.com
Fri Dec 17 18:46:57 CET 2010


In the process of migrating from the classic API I have
found what appears to be a problem with Rcpp::Datetime.
There is no unit test for this situation.

Rcpp::Datetime dt("2015-04-15 06:00:00")
and
Rcpp::Datetime dt("2015-04-15 06:00:00.0")
both fail due to a type conversion error.

Here is the original constructor:
Datetime::Datetime(const std::string &s, const std::string &fmt) {
        Rcpp::Function strptime("strptime");    // we cheat and call
strptime() from R
        m_dt = Rcpp::as<double>(strptime(s, fmt));
        update_tm();
}

The problem is that strptime() returns POSIXlt type, not POSIXct type.
Adding Rcpp::Function asPOSIXct("as.POSIXct") and using it
to convert seems to fix the problem.

Dominick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101217/31931b3e/attachment-0001.htm>


More information about the Rcpp-devel mailing list