<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/tidytext-0-1-4/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://juliasilge.com/blog/tidytext-0-1-4/"> Rstats on Julia Silge</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I am pleased to announce that <a rel="nofollow" href="https://cran.r-project.org/package=tidytext" target="_blank">tidytext 0.1.4</a> is now on CRAN!</p>
<p>This release of our package for text mining using tidy data principles has an excellent collection of delightfulness in it. First off, all the important functions in tidytext now support support non-standard evaluation through the <a rel="nofollow" href="http://dplyr.tidyverse.org/articles/programming.html" target="_blank">tidyeval framework</a>.</p>
<pre><code>library(janeaustenr)
library(tidytext)
library(dplyr)

input_var &lt;- quo(text)
output_var &lt;- quo(word)

data_frame(text = prideprejudice) %>%
    unnest_tokens(!! output_var, !! input_var)</code></pre>
<pre><code>## # A tibble: 122,204 x 1
##         word
##        </code></pre>
<p>It’s been a long time coming but I finally moved my blog from Jekyll/Bootstrap on Github pages to blogdown, Hugo and <a rel="nofollow" href="https://www.netlify.com/" target="_blank">Netlify</a>! Moreover, I also now have my own domain name <a rel="nofollow" href="https://www.shirin-glander.de/" target="_blank">www.shirin-glander.de</a>. <img alt="🙂" src="https://s.w.org/images/core/emoji/2/72x72/1f642.png" class="wp-smiley"></p>
<p>I followed the <a rel="nofollow" href="https://bookdown.org/yihui/blogdown/" target="_blank">blogdown ebook</a> to set up my blog. I chose Thibaud Leprêtre’s <a rel="nofollow" href="https://themes.gohugo.io/hugo-tranquilpeak-theme/" target="_blank">tranquilpeak theme</a>. It looks much more polished than my old blog.</p>
<p>My old blog will remain where it is, so that all the links that are out there will still work (and I don’t have to go through the hassle of migrating all my posts to my new site).</p>
<p>From this point on, all new posts will go up on <a rel="nofollow" href="https://www.shirin-glander.de/" target="_blank">my new page</a>!</p>
	<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/2uC9MDKpAOc" height="1">
<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/tidyrspread-and-dplyrrename_at-in-action/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.brodrigues.co/blog/2017-07-27-spread_rename_at/"> Econometrics and Free Software</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I was recently confronted to a situation that required going from a long dataset to a wide dataset, but with a small twist: there were two datasets, which I had to merge into one. You might wonder what kinda crappy twist that is, right? Well, let’s take a look at the data:<br>
data1; data2 ## # A tibble: 20 x 4 ## country date variable_1 value ##
<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/how-to-make-maps-with-census-data-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://randomjohn.github.io/r-maps-with-census-data/"> randomjohn.github.io</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>US Census Data</h2>
<p>The US Census collects a number of demographic measures and publishes aggregate data through its website. There are several ways to use Census data in R, from the <a rel="nofollow" href="https://www.census.gov/developers/" target="_blank">Census API</a> to the <a rel="nofollow" href="https://www.jstatsoft.org/article/view/v037i06" target="_blank">USCensus2010</a> package. If you are interested in geopolitical data in the US, I recommend exploring both these options – the Census API requires a key for each person who uses it, and the package requires downloading a very large dataset. The setups for both require some effort, but once that effort is done you don’t have to do it again.</p>
<p>The <code>acs</code> package in R allows you to access the Census API easily. I highly recommend checking it out, and that’s the method we will use here. Note that I’ve already defined the variable <code>api_key</code> – if you are trying to run this code you will need to first run something like <code>api_key &lt;- </code>
<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/using-wraprlet-with-tidyeval/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2017/06/using-wraprlet-with-tidyeval/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>While going over some of the discussion related to <a rel="nofollow" href="http://www.win-vector.com/blog/2017/06/please-consider-using-wraprlet-for-replacement-tasks/" target="_blank">my last post</a> I came up with a really neat way to use <code>wrapr::let()</code> and <code>rlang</code>/<code>tidyeval</code> together.</p>
<p>Please read on to see the situation and example.<span></span>Suppose we want to parameterize over a couple of names, one denoting a variable coming from the current environment and one denoting a column name. Further suppose we are worried the two names may be the same. </p>
<p>We can actually handle this quite neatly, using <code>rlang</code>/<code>tidyeval</code> to denote intent (in this case using “<code>!!</code>” to specify “take from environment instead of the data frame”) and allowing <code>wrapr::let()</code> to perform the substitutions.</p>
<pre>
suppressPackageStartupMessages(library(&quot;dplyr&quot;))
library(&quot;wrapr&quot;)

mass_col_name = 'mass'
mass_const_name = 'mass'

mass &lt;- 100

let(
  c(MASS_COL = mass_col_name,
    MASS_CONST = mass_const_name),
  
  starwars %>%
    transmute(height,
              (!! MASS_CONST), # `mass` from environment
              MASS_COL,        # `mass` from data.frame
              h100 = height * (!! MASS_CONST),  # env
              hm = height * MASS_COL            # data
    ) %>%
    head()
)

#> # A tibble: 6 x 5
#>   height `(100)`  mass  h100    hm
#>    </pre>
<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/please-consider-using-wraprlet-for-replacement-tasks/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2017/06/please-consider-using-wraprlet-for-replacement-tasks/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>From <a rel="nofollow" href="https://github.com/tidyverse/dplyr/issues/2916" target="_blank"><code>dplyr</code> issue 2916</a>.</p>
<p>The following <em>appears</em> to work.</p>
<div>
<pre><code><span>suppressPackageStartupMessages</span>(<span>library</span>(<span>&quot;dplyr&quot;</span>))

COL &lt;-<span> &quot;homeworld&quot;</span>
starwars %>%
<span> </span><span>group_by</span>(.data[[COL]]) %>%
<span> </span><span>head</span>(<span>n=</span><span>1</span>)</code></pre>
</div>
<pre><code>## # A tibble: 1 x 14
## # Groups:   COL [1]
##             name height  mass hair_color skin_color eye_color birth_year
##            </code></pre>
<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/check-data-quality-with-padr/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://edwinth.github.io/blog/data-quality-padr/"> That’s so Random</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The <code>padr</code> package was designed to prepare datetime data for analysis. That is, to take raw, timestamped data, and quickly convert it into a tidy format that can be analyzed with all the tidyverse tools. Recently, a colleague and I discovered a second use for the package that I had not anticipated: checking data quality. Every analysis should contain checking if data are as expected. In the case of timestamped data, observations are sometimes missing due to technical malfunction of the system that produced them. Here are two examples that show how <code>pad</code> and <code>thicken</code> can be leveraged to detect problems in timestamped data quickly.</p>
<h2>Regular observations</h2>
<p>Lets imagine our system produces a value every five minutes. We want to analyse the data of the last couple of months and start by some routine checks. We quickly find that the number of records is not what we expected.</p>
<div>
<pre><code><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>padr</span><span>)</span><span>
</span><span>regular_system</span><span> </span><span>%>%</span><span> </span><span>head</span><span>
</span></code></pre>
</div>
<div>
<pre><code>## # A tibble: 6 x 2
##             timestamp  value
##                </code></pre></div>
<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/there-is-usually-more-than-one-way-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2017/06/there-is-usually-more-than-one-way-in-r/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Python has a fairly famous design principle (from <a rel="nofollow" href="https://www.python.org/dev/peps/pep-0020/" target="_blank">“PEP 20 — The Zen of Python”</a>):</p>
<blockquote><p>There should be one– and preferably only one –obvious way to do it.</p>
</blockquote>
<p>Frankly in <a rel="nofollow" href="https://www.r-project.org/" target="_blank"><code>R</code> </a> (especially once you add many packages) there is usually more than one way. As an example we will talk about the common <code>R</code> functions: <code>str()</code>, <code>head()</code>, and the <a rel="nofollow" href="https://cran.r-project.org/package=tibble" target="_blank"><code>tibble package</code></a>‘s <code>glimpse()</code>.<span></span></p>
<p>
<h2><code>tibble::glimpse()</code></h2>
<p>Consider the important task inspecting a <code>data.frame</code> to see column types and a few example values. The <code>dplyr</code>/<code>tibble</code>/<code>tidyverse</code> way of doing this is as follows:</p>
<pre>
library(&quot;tibble&quot;)
glimpse(mtcars)

Observations: 32
Variables: 11
$ mpg  </pre>