[Rcpp-devel] Datetime and DatetimeVector definitions

Jason Lessels jlessels at gmail.com
Thu May 19 11:00:51 CEST 2011

I have a very limited understanding of the class definition, but i was wondering if I could make a request for a minor change in relation to the two classes Datetime and the extension DatetimeVector. I have been successfully using Datetime class, passing both the date string and the format string, as this is allowed with the following definition;

00047	 Datetime::Datetime(const std::string &s, const std::string &fmt) {
00048                 Rcpp::Function strptime("strptime");    // we cheat and call strptime() from R
00049                 Rcpp::Function asPOSIXct("as.POSIXct"); // and we need to convert to POSIXct
00050                 m_dt = Rcpp::as<double>(asPOSIXct(strptime(s, fmt)));
00051                 update_tm();
00052     }

however the DatetimeVector definition uses;

00027         DatetimeVector::DatetimeVector(SEXP vec) throw(std::range_error) : v()  {
00028                 int i;
00029                 if (!Rf_isNumeric(vec) || Rf_isMatrix(vec) || Rf_isLogical(vec))
00030                         throw std::range_error("DatetimeVector: invalid numeric vector in constructor");
00031                 int len = Rf_length(vec);
00032                 if (len == 0)
00033                         throw std::range_error("DatetimeVector: null vector in constructor");
00034                 v.resize(len);
00035                 for (i = 0; i < len; i++)
00036                         v[i] = Datetime( static_cast<double>(REAL(vec)[i]));
00037         }

where line 36 calls Datetime without the ability to provide the format. Would it be possible for this to be changed to allow the format of the Datetime string. Currently I have to either convert the date string in R, or use an additional loop to convert the format, which make this slower than using the standard methods in R.

Sorry in advance if my understanding is incorrect.

More information about the Rcpp-devel mailing list