<p>Very happy to announce a new package of mine is now up on the <a href="https://cran.r-project.org/">CRAN</a> repository network: <a href="http://dirk.eddelbuettel.com/code/rapidatetime.html">RApiDatetime</a>.</p>
<p>It provides six entry points for C-level functions of the R API for <code>Date</code> and <code>Datetime</code> calculations: <code>asPOSIXlt</code> and <code>asPOSIXct</code> convert between long and compact datetime representation, <code>formatPOSIXlt</code> and <code>Rstrptime</code> convert to and from character strings, and <code>POSIXlt2D</code> and <code>D2POSIXlt</code> convert between <code>Date</code> and <code>POSIXlt</code> datetime. These six functions are all fairly essential and useful, but not one of them was previously exported by R. Hence the need to put them together in the this package to complete the accessible API somewhat.</p>
<p>These should be helpful for fellow package authors as many of us have either our own partial copies of some of this code, or rather farm back out into R to get this done.</p>
<p>As a simple (yet real!) illustration, here is an actual <a href="https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/api/meat/Datetime.h#L30-L34">Rcpp function</a> which we could now cover at the C level rather than having to go back up to R (via <code>Rcpp::Function()</code>):</p>
<div><pre><code>    <span>inline</span> Datetime::Datetime(<span>const</span> std::string &amp;s, <span>const</span> std::string &amp;fmt) {
        Rcpp::Function strptime(<span>&quot;strptime&quot;</span>);    <span>// we cheat and call strptime() from R</span>
        Rcpp::Function asPOSIXct(<span>&quot;as.POSIXct&quot;</span>); <span>// and we need to convert to POSIXct</span>
        m_dt = Rcpp::as&lt;<span>double</span>>(asPOSIXct(strptime(s, fmt)));
        update_tm();
    }</code></pre></div>
<p>I had taken a first brief stab at this about two years ago, but never finished. With the recent emphasis on C-level function registration, coupled with a possible use case from <a href="http://dirk.eddelbuettel.com/code/anytime.html">anytime</a> I more or less put this together last weekend.</p>
<p>It currently builds and tests fine on POSIX-alike operating systems. If someone with some skill and patience in working on Windows would like to help complete the Windows side of things then I would certainly welcome help and pull requests.</p>
<p>For questions or comments please use the <a href="https://github.com/eddelbuettel/rapidatetime/issues">issue tracker</a> off the <a href="https://github.com/eddelbuettel/rapidatetime">GitHub repo</a>.</p>
<p>
This post by <a href="http://dirk.eddelbuettel.com/">Dirk Eddelbuettel</a> originated on his <a href="http://dirk.eddelbuettel.com/blog/">Thinking inside the box</a> blog. Please report excessive re-aggregation in third-party for-profit settings.
</p><p>