<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/tidyer-bls-data-with-the-blscarper-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.datascienceriot.com//r/tidyblscar/"> Data Science Riot!</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The recent release of the <a rel="nofollow" href="https://github.com/keberwein/blscrapeR" target="_blank">blscrapeR</a> package brings the “tidyverse” into the fold. Inspired by my recent collaboration with Kyle Walker on his excellent <a rel="nofollow" href="https://github.com/walkerke/tidycensus" target="_blank">tidycensus</a> package, blscrapeR has been optimized for use within the tidyverse as of the current version 3.0.0.</p>
<h2>New things you’ll notice right away include:</h2>
<ul>
<li>
<p>All data now returned as tibbles.</p>
</li>
<li>
<p>dplyr and purrr are now imported packages, along with magrittr and ggplot, which were imported from the start.</p>
</li>
<li>
<p>No need to call any packages other than tidyverse and blscrapeR.</p>
</li>
</ul>
<h2>Major internal changes</h2>
<ul>
<li>
<p>Switched from base R to dplyr in instances where performance could be increased.</p>
</li>
<li>
<p>Standard apply functions replaced with purrr <code>map()</code> functions where performance could be increased.</p>
</li>
</ul>
<figure>
<pre><code data-lang="r"><span>install.packages</span><span>(</span><span>&quot;blscrapeR&quot;</span><span>)</span></code></pre>
</figure>
<h2>The BLS: More than Unemployment</h2>
<p>The American Time Use Survey is one of the BLS’ more interesting data sets. Below is an API query that compares the time Americans spend watching TV on a daily basis compared to the time spent socializing and communicating.</p>
<p>It should be noted, some familiarity with BLS series id numbers is required here. The <a rel="nofollow" href="https://beta.bls.gov/dataQuery/search" target="_blank">BLS Data Finder</a> is a nice tool to find series id numbers.</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>blscrapeR</span><span>)</span><span>
</span><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>tbl</span><span> </span><span>&lt;-</span><span> </span><span>bls_api</span><span>(</span><span>c</span><span>(</span><span>&quot;TUU10101AA01014236&quot;</span><span>,</span><span> </span><span>&quot;TUU10101AA01013951&quot;</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>spread</span><span>(</span><span>seriesID</span><span>,</span><span> </span><span>value</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>dateCast</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>rename</span><span>(</span><span>watching_tv</span><span> </span><span>=</span><span> </span><span>TUU10101AA01014236</span><span>,</span><span> </span><span>socializing_communicating</span><span> </span><span>=</span><span> </span><span>TUU10101AA01013951</span><span>)</span><span>
</span><span>tbl</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## # A tibble: 3 x 7
##    year    period periodName footnotes socializing_communicating watching_tv       date
## * </code></pre></figure>