<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/a-quick-worldemojiday-exploration/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://colinfay.me/worldemojiday"> Colin Fay</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Let’s celebrate #WorldEmojiDay with a quick exploration of my <a rel="nofollow" href="https://twitter.com/_ColinFay" target="_blank">own<br>
twitter account</a>.</p>
<h2>The <img alt="📦" src="https://s.w.org/images/core/emoji/2.4/72x72/1f4e6.png" class="wp-smiley"></h2>
<p>We’ll need:</p>
<h4>From Github</h4>
<ul>
<li><code>{emo}</code></li>
</ul>
<p></p>
<div>
<div>
<pre><code><span>remote</span><span>::</span><span>install_github</span><span>(</span><span>&quot;hadley/emo&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<h4>From CRAN</h4>
<ul>
<li><code>{dplyr}</code></li>
<li><code>{tidyr}</code></li>
<li><code>{rtweet}</code></li>
<li><code>{tidytext}</code></li>
</ul>
<blockquote>
<p>Note: This page has been created at:</p>
</blockquote>
<div>
<div>
<pre><code><span>Sys.time</span><span>()</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## [1] &quot;2018-07-17 17:22:29 CEST&quot;
</code></pre>
</div>
</div>
<h2>The <img alt="🔍" src="https://s.w.org/images/core/emoji/2.4/72x72/1f50d.png" class="wp-smiley"></h2>
<p>Let’s get my last 3200 tweets:</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>emo</span><span>)</span><span>
</span><span>library</span><span>(</span><span>rtweet</span><span>)</span><span>
</span><span>library</span><span>(</span><span>dplyr</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## 
## Attaching package: 'dplyr'

## The following objects are masked from 'package:stats':
## 
##     filter, lag

## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
</code></pre>
</div>
</div>
<div>
<div>
<pre><code><span>res</span><span> </span><span>&lt;-</span><span> </span><span>get_timeline</span><span>(</span><span>
</span><span>&quot;_ColinFay&quot;</span><span>,</span><span>
</span><span>n</span><span> </span><span>=</span><span> </span><span>3200</span><span>
</span><span>)</span><span>
</span><span>names</span><span>(</span><span>res</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>##  [1] &quot;user_id&quot;                 &quot;status_id&quot;              
##  [3] &quot;created_at&quot;              &quot;screen_name&quot;            
##  [5] &quot;text&quot;                    &quot;source&quot;                 
##  [7] &quot;display_text_width&quot;      &quot;reply_to_status_id&quot;     
##  [9] &quot;reply_to_user_id&quot;        &quot;reply_to_screen_name&quot;   
## [11] &quot;is_quote&quot;                &quot;is_retweet&quot;             
## [13] &quot;favorite_count&quot;          &quot;retweet_count&quot;          
## [15] &quot;hashtags&quot;                &quot;symbols&quot;                
## [17] &quot;urls_url&quot;                &quot;urls_t.co&quot;              
## [19] &quot;urls_expanded_url&quot;       &quot;media_url&quot;              
## [21] &quot;media_t.co&quot;              &quot;media_expanded_url&quot;     
## [23] &quot;media_type&quot;              &quot;ext_media_url&quot;          
## [25] &quot;ext_media_t.co&quot;          &quot;ext_media_expanded_url&quot; 
## [27] &quot;ext_media_type&quot;          &quot;mentions_user_id&quot;       
## [29] &quot;mentions_screen_name&quot;    &quot;lang&quot;                   
## [31] &quot;quoted_status_id&quot;        &quot;quoted_text&quot;            
## [33] &quot;quoted_created_at&quot;       &quot;quoted_source&quot;          
## [35] &quot;quoted_favorite_count&quot;   &quot;quoted_retweet_count&quot;   
## [37] &quot;quoted_user_id&quot;          &quot;quoted_screen_name&quot;     
## [39] &quot;quoted_name&quot;             &quot;quoted_followers_count&quot; 
## [41] &quot;quoted_friends_count&quot;    &quot;quoted_statuses_count&quot;  
## [43] &quot;quoted_location&quot;         &quot;quoted_description&quot;     
## [45] &quot;quoted_verified&quot;         &quot;retweet_status_id&quot;      
## [47] &quot;retweet_text&quot;            &quot;retweet_created_at&quot;     
## [49] &quot;retweet_source&quot;          &quot;retweet_favorite_count&quot; 
## [51] &quot;retweet_retweet_count&quot;   &quot;retweet_user_id&quot;        
## [53] &quot;retweet_screen_name&quot;     &quot;retweet_name&quot;           
## [55] &quot;retweet_followers_count&quot; &quot;retweet_friends_count&quot;  
## [57] &quot;retweet_statuses_count&quot;  &quot;retweet_location&quot;       
## [59] &quot;retweet_description&quot;     &quot;retweet_verified&quot;       
## [61] &quot;place_url&quot;               &quot;place_name&quot;             
## [63] &quot;place_full_name&quot;         &quot;place_type&quot;             
## [65] &quot;country&quot;                 &quot;country_code&quot;           
## [67] &quot;geo_coords&quot;              &quot;coords_coords&quot;          
## [69] &quot;bbox_coords&quot;             &quot;status_url&quot;             
## [71] &quot;name&quot;                    &quot;location&quot;               
## [73] &quot;description&quot;             &quot;url&quot;                    
## [75] &quot;protected&quot;               &quot;followers_count&quot;        
## [77] &quot;friends_count&quot;           &quot;listed_count&quot;           
## [79] &quot;statuses_count&quot;          &quot;favourites_count&quot;       
## [81] &quot;account_created_at&quot;      &quot;verified&quot;               
## [83] &quot;profile_url&quot;             &quot;profile_expanded_url&quot;   
## [85] &quot;account_lang&quot;            &quot;profile_banner_url&quot;     
## [87] &quot;profile_background_url&quot;  &quot;profile_image_url&quot;
</code></pre>
</div>
</div>
<p>Here is what the <code>text</code> column looks like:</p>
<div>
<div>
<pre><code><span>res</span><span> </span><span>%>%</span><span> </span><span>pull</span><span>(</span><span>text</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>.</span><span>[</span><span>1</span><span>:</span><span>5</span><span>]</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## [1] &quot;@GoldbergData It adds a little label at the top left with the text you provide. \nCan be useful if you want to add some legends in a markdown / shiny app, for example&quot;
## [2] &quot;#RStats \nCool new feature in ggplot2 v3 — tagging plots : https://t.co/jFUqX2Tj5T&quot;                                                                                    
## [3] &quot;#RStats — A perfect introduction to \U0001f5fa with the {sf} \U0001f4e6 &amp; Co by @statnmap : \nhttps://t.co/IrmcSBDMDy https://t.co/m3TyUjrxYF&quot;                     
## [4] &quot;@vsbuffalo Amen to that&quot;                                                                                                                                               
## [5] &quot;#RStats — \U0001f680 Setting up RStudio Server, Shiny Server and PostgreSQL :\nhttps://t.co/J1Y7edNAj0&quot;
</code></pre>
</div>
</div>
<p>As you can see, the emojis are not printed in the console, but converted<br>
to weird characters like <code>\U0001f4e6</code> and such. These are unicode<br>
characters: translations of the emojis into a language your machine can<br>
understand. I won’t go deeper into this, here are two resources you can<br>
read if you want to know more about encoding:</p>
<ul>
<li>
<p><a rel="nofollow" href="https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/" target="_blank">The Absolute Minimum Every Software Developer Absolutely,<br>
Positively Must Know About Unicode and Character Sets (No<br>
Excuses!)</a></p>
</li>
<li>
<p><a rel="nofollow" href="https://www.codenewbie.org/blogs/what-emojis-tell-us-about-encoding" target="_blank">What emojis tell us about<br>
encoding</a></p>
</li>
</ul>
<h2>The <img alt="📊" src="https://s.w.org/images/core/emoji/2.4/72x72/1f4ca.png" class="wp-smiley"></h2>
<p>Let’s use the <code>{emo}</code> package to extract the emojis from the text.<br>
Inspired by <code>{stringr}</code>, this package has a <code>ji_extract_all</code> function<br>
that is designed to <strong>extract all the emojis from a character vector</strong>.<br>
We’ll use it on out text column, then extract the date and emo column.<br>
We then pass the result to <code>tidyr::unnest</code> in order to remove the empty<br>
emo rows (i.e, the tweets without an emoji).</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>tidyr</span><span>)</span><span>
</span><span>emos</span><span> </span><span>&lt;-</span><span> </span><span>res</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>
</span><span>emo</span><span> </span><span>=</span><span> </span><span>ji_extract_all</span><span>(</span><span>text</span><span>)</span><span>
</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>select</span><span>(</span><span>created_at</span><span>,</span><span>emo</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>unnest</span><span>(</span><span>emo</span><span>)</span><span>
</span><span>emos</span><span>
</span></code></pre>
</div>
</div>
<div>
<div>
<pre><code>## # A tibble: 887 x 2
##    created_at          emo  
##    </code></pre></div></div>