<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/rcppcctz-0-0-5/"></div></div><div><a data-url="http://www.r-bloggers.com/rcppcctz-0-0-5/" data-counturl="http://www.r-bloggers.com/rcppcctz-0-0-5/" data-count="horizontal" data-text="RcppCCTZ 0.0.5" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://dirk.eddelbuettel.com/blog/2016/07/21#rcppcctz_0.0.5"> Thinking inside the box </a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Version 0.0.5 of <a target="_blank" href="http://dirk.eddelbuettel.com/code/rcpp.cctz.html">RcppCCTZ</a> arrived on <a target="_blank" href="https://cloud.r-project.org/">CRAN</a> a couple of days ago. It reflects an upstream fixed made a few weeks ago. <a target="_blank" href="https://cloud.r-project.org/">CRAN</a> tests revealed that <code>g++-6</code> was tripping over one missing <code>#define</code>; this was added <a target="_blank" href="https://github.com/google/cctz/commit/6bff56627bcb385234055ebf8c557683758f237c">upstream</a> and I subsequently synchronized with upstream. At the same time the set of examples was extended (see below).</p>
<p>Somehow <a target="_blank" href="https://user2016.org/">useR! 2016</a> got in the way and while working on the then-incomplete examples during the traveling I forgot to release this until <a target="_blank" href="https://cloud.r-project.org/">CRAN</a> reminded me that their tests still failed. I promptly prepared the 0.0.5 release but somehow failed to update NEWS files etc. They are correct in the repo but not in the shipped package. Oh well.</p>
<p><a target="_blank" href="https://github.com/google/cctz">CCTZ</a> is <em>a C++ library for translating between absolute and civil times using the rules of a time zone</em>. In fact, it is <em>two</em> libraries. One for dealing with <em>civil time</em>: human-readable dates and time, and one for converting between between absolute and civil times via time zones. It requires only a proper C++11 compiler and the standard IANA time zone data base which standard Unix, Linux, OS X, … computers tend to have in <code>/usr/share/zoneinfo</code>. <a target="_blank" href="http://dirk.eddelbuettel.com/code/rcpp.cctz.html">RcppCCTZ</a> connects this library to R by relying on <a target="_blank" href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a>.</p>
<p>Two good examples are now included, and shown here. The first one tabulates the time difference between New York and London (at a weekly level for compactness):</p>
<div>
<pre><code>R><span> </span><span>example</span>(tzDiff)

tzDiffR><span> </span><span># simple call: difference now</span>
tzDiffR><span> </span><span>tzDiff</span>(<span>&quot;America/New_York&quot;</span>, <span>&quot;Europe/London&quot;</span>, <span>Sys.time</span>())
[<span>1</span>] <span>5</span>

tzDiffR><span> </span><span># tabulate difference for every week of the year</span>
tzDiffR><span> </span><span>table</span>(<span>sapply</span>(<span>0</span>:<span>52</span>, function(d) <span>tzDiff</span>(<span>&quot;America/New_York&quot;</span>, <span>&quot;Europe/London&quot;</span>,
tzDiff+<span> </span><span>as.POSIXct</span>(<span>as.Date</span>(<span>&quot;2016-01-01&quot;</span>) +<span> </span>d*<span>7</span>))))

 <span>4</span>  <span>5</span> 
 <span>3</span> <span>50</span> 
R><span> </span></code></pre>
</div>
<p>Because the two continents happen to <em>spring forward</em> and <em>fall backwards</em> between regular and daylight savings times, there are, respectively, two and one week periods where the difference is one hour less than usual.</p>
<p>A second example shifts the time to a different time zone:</p>
<div>
<pre><code>R><span> </span><span>example</span>(toTz)

toTzR><span> </span><span>toTz</span>(<span>Sys.time</span>(), <span>&quot;America/New_York&quot;</span>, <span>&quot;Europe/London&quot;</span>)
[<span>1</span>] <span>&quot;2016-07-14 10:28:39.91740 CDT&quot;</span>
R><span> </span></code></pre>
</div>
<p>Note that because we return a <code>POSIXct</code> object, it is printed by R with the default (local) TZ attribute (for &quot;America/Chicago&quot; in my case). A more direct example asks what time it is in my time zone when it is midnight in Tokyo:</p>
<div>
<pre><code>R><span> </span><span>toTz</span>(<span>ISOdatetime</span>(<span>2016</span>,<span>7</span>,<span>15</span>,<span>0</span>,<span>0</span>,<span>0</span>), <span>&quot;Japan&quot;</span>, <span>&quot;America/Chicago&quot;</span>)
[<span>1</span>] <span>&quot;2016-07-14 15:00:00 CDT&quot;</span>
R></code></pre>
</div>
<p>More changes will come in 0.0.6 as soon as I find time to translate the nice <code>time_tool</code> (command-line) example into an R function.</p>
<p>Changes in this version are summarized here:</p>
<blockquote>
<h4>
Changes in version 0.0.5 (2016-07-09)<br>
</h4>
<ul>
<li>
<p>
New utility example functions <code>toTz()</code> and <code>tzDiff</code>
</p>
</li>
<li>
<p>
Synchronized with small upstream change for additional <code>#ifdef</code> for compiler differentiation
</p>
</li>
</ul>
</blockquote>
<p>We also have a <a target="_blank" href="http://dirk.eddelbuettel.com/cranberries/2016/07/10#RcppCCTZ_0.0.5">diff to the previous version</a> thanks to <a target="_blank" href="http://dirk.eddelbuettel.com/cranberries">CRANberries</a>. More details are at the <a target="_blank" href="http://dirk.eddelbuettel.com/code/rcpp.cctz.html">RcppCCTZ page</a>; code, issue tickets etc at the <a target="_blank" href="https://github.com/eddelbuettel/rcppcctz">GitHub repository</a>.</p>
<p>
This post by <a target="_blank" href="http://dirk.eddelbuettel.com/">Dirk Eddelbuettel</a> originated on his <a target="_blank" 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>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/rcppcctz-0-0-5/"></div></div><div><a data-url="http://www.r-bloggers.com/rcppcctz-0-0-5/" data-counturl="http://www.r-bloggers.com/rcppcctz-0-0-5/" data-count="vertical" data-text="RcppCCTZ 0.0.5" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://dirk.eddelbuettel.com/blog/2016/07/21#rcppcctz_0.0.5"> Thinking inside the box </a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/EFA1UOWdDTU"></a></div>