<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/my-best9of2017-tweets/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.masalmon.eu/2017/12/30/best9of2017/"> Maëlle</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>You’ve probably seen people posting their #Best9of2017, primarily on Instagram I’d say. I’m not an Instagram user, although I do have an account to spy on my younger sister and cousins, so I don’t even have 9 Instagram posts in total but I do love the collage people get to show off… So what about my best 9 <em>tweets</em> of 2017?</p>
<p><span></span></p>
<h1>Get my 9 best tweets by number of likes</h1>
<p>I first wanted to use <code>rtweet::get_timeline</code> but it only returned me tweets from July, even when using <code>include_rts = FALSE</code>, so I downloaded my analytics files from the Twitter website, one per trimester.</p>
<div>
<div>
<pre><code><span>my_files</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;tweet_activity_metrics_ma_salmon_20170101_20170402_en.csv&quot;</span><span>,</span><span>
</span><span>&quot;tweet_activity_metrics_ma_salmon_20170402_20170702_en.csv&quot;</span><span>,</span><span>
</span><span>&quot;tweet_activity_metrics_ma_salmon_20170702_20171001_en.csv&quot;</span><span>,</span><span>
</span><span>&quot;tweet_activity_metrics_ma_salmon_20171001_20171231_en.csv&quot;</span><span>)</span><span>
</span><span>paths</span><span> </span><span>&lt;-</span><span> </span><span>paste0</span><span>(</span><span>&quot;data/&quot;</span><span>,</span><span> </span><span>my_files</span><span>)</span><span>
</span><span># read them all at once</span><span>
</span><span>my_tweets</span><span> </span><span>&lt;-</span><span> </span><span>purrr</span><span>::</span><span>map_df</span><span>(</span><span>paths</span><span>,</span><span> </span><span>readr</span><span>::</span><span>read_csv</span><span>)</span><span>
</span><span># just in case I got some data ranges wrong</span><span>
</span><span>my_tweets</span><span> </span><span>&lt;-</span><span> </span><span>unique</span><span>(</span><span>my_tweets</span><span>)</span><span>
</span><span># get the top 9!</span><span>
</span><span>my_tweets</span><span> </span><span>&lt;-</span><span> </span><span>dplyr</span><span>::</span><span>arrange</span><span>(</span><span>my_tweets</span><span>,</span><span> </span><span>-</span><span> </span><span>likes</span><span>)</span><span>
</span><span>my_tweets</span><span> </span><span>&lt;-</span><span> </span><span>janitor</span><span>::</span><span>clean_names</span><span>(</span><span>my_tweets</span><span>)</span><span>
</span><span>best9</span><span> </span><span>&lt;-</span><span> </span><span>my_tweets</span><span>$</span><span>tweet_permalink</span><span>[</span><span>1</span><span>:</span><span>9</span><span>]</span><span>
</span></code></pre>
</div>
</div>
<p>My husband advised me to use something more elaborate than number of likes, which is a wise idea, but I was happy with that simple method.</p>
<h1>Take screenshots and paste them</h1>
<p>There’s a great R package to do screenshots from R, <a rel="nofollow" href="https://cran.r-project.org/web/packages/webshot/vignettes/intro.html" target="_blank"><code>webshot</code></a>. I was a bit annoyed at the “Follow” button appearing, but I did not want to have to write Javascript code to first login in the hope to make that thing disappear. I tried using a CSS selector instead of a rectangle, but I was less satisfied. An obvious problem here is that contrary to Instagram images, tweets have different heights depending on the text length and on the size of the optional attached media… It’s a bit sad but not too sad, my collage will still give a look at my Twitter 2017.</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>&quot;magrittr&quot;</span><span>)</span><span>
</span><span>save_one_file</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>url</span><span>,</span><span> </span><span>name</span><span>){</span><span>
</span><span>filename</span><span> </span><span>&lt;-</span><span> </span><span>paste0</span><span>(</span><span>name</span><span>,</span><span> </span><span>&quot;.png&quot;</span><span>)</span><span>
</span><span># save and output filename</span><span>
</span><span>webshot</span><span>::</span><span>webshot</span><span>(</span><span>url</span><span>,</span><span> </span><span>filename</span><span>,</span><span>
</span><span>cliprect</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0</span><span>,</span><span> </span><span>150</span><span>,</span><span> </span><span>750</span><span>,</span><span> </span><span>750</span><span>))</span><span>
</span><span>filename</span><span>
</span><span>}</span><span>
</span><span>files</span><span> </span><span>&lt;-</span><span> </span><span>purrr</span><span>::</span><span>map2_chr</span><span>(</span><span>best9</span><span>,</span><span> </span><span>1</span><span>:</span><span>9</span><span>,</span><span> </span><span>save_one_file</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>Regarding the collage part using <code>magick</code>, I used my <a rel="nofollow" href="http://www.masalmon.eu/2017/03/19/facesofr/" target="_blank">“Faces of R” post</a> as a reference, which is funny since it features in my top 9 tweets.</p>
<div>
<div>
<pre><code><span>no_rows</span><span> </span><span>&lt;-</span><span> </span><span>3</span><span>
</span><span>no_cols</span><span> </span><span>&lt;-</span><span> </span><span>3</span><span>
</span><span>make_column</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>i</span><span>,</span><span> </span><span>files</span><span>,</span><span> </span><span>no_rows</span><span>){</span><span>
</span><span>filename</span><span> </span><span>&lt;-</span><span> </span><span>paste0</span><span>(</span><span>&quot;col&quot;</span><span>,</span><span> </span><span>i</span><span>,</span><span> </span><span>&quot;.jpg&quot;</span><span>)</span><span>
</span><span>magick</span><span>::</span><span>image_read</span><span>(</span><span>files</span><span>[(</span><span>i</span><span>*</span><span>no_rows</span><span>+1</span><span>)</span><span>:</span><span>((</span><span>i</span><span>+1</span><span>)</span><span>*</span><span>no_rows</span><span>)])</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_border</span><span>(</span><span>&quot;salmon&quot;</span><span>,</span><span> </span><span>&quot;20x20&quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_append</span><span>(</span><span>stack</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_write</span><span>(</span><span>filename</span><span>)</span><span>
</span><span>filename</span><span>
</span><span>}</span><span>
</span><span>purrr</span><span>::</span><span>map_chr</span><span>(</span><span>0</span><span>:</span><span>(</span><span>no_cols</span><span>-1</span><span>),</span><span> </span><span>make_column</span><span>,</span><span> </span><span>files</span><span> </span><span>=</span><span> </span><span>files</span><span>,</span><span>
</span><span>no_rows</span><span> </span><span>=</span><span> </span><span>no_rows</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_read</span><span>()</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_append</span><span>(</span><span>stack</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_border</span><span>(</span><span>&quot;salmon&quot;</span><span>,</span><span> </span><span>&quot;20x20&quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>magick</span><span>::</span><span>image_write</span><span>(</span><span>&quot;2017-12-30-best9of2017.jpg&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>And since I’m well behaved, I clean after myself.</p>
<div>
<div>
<pre><code><span># clean </span><span>
</span><span>file.remove</span><span>(</span><span>files</span><span>)</span><span>
</span><span>file.removes</span><span>(</span><span>paste0</span><span>(</span><span>&quot;col&quot;</span><span>,</span><span> </span><span>1</span><span>:</span><span>3</span><span>,</span><span> </span><span>&quot;.jpg&quot;</span><span>))</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="" src="https://i1.wp.com/raw.githubusercontent.com/maelle/maelle.github.io/master/_source/2017-12-30-best9of2017.jpg?w=456&ssl=1" data-recalc-dims="1"></p>
<p>So, apart from fun blog posts (<a rel="nofollow" href="http://www.masalmon.eu/2017/11/16/wheretoliveus/" target="_blank">Where to live in the US</a>, <a rel="nofollow" href="http://www.masalmon.eu/2017/03/19/facesofr/" target="_blank">Faces of #rstats Twitter</a>, <a rel="nofollow" href="http://www.masalmon.eu/2017/02/18/complot/" target="_blank">A plot against the CatterPlots complot</a>) and more serious ones (<a rel="nofollow" href="http://www.masalmon.eu/2017/06/17/automatictools/" target="_blank">Automatic tools for improving R packages</a>, <a rel="nofollow" href="http://www.masalmon.eu/2017/12/11/goodrpackages/" target="_blank">How to develop good R packages (for open science)</a>, <a rel="nofollow" href="http://www.masalmon.eu/2017/12/21/wherehaveyoubeen/" target="_blank">Where have you been? Getting my Github activity</a>), my top 9 tweets include a good <code>ggplot2</code> tip (<a rel="nofollow" href="http://www.ggplot2-exts.org/" target="_blank">this website</a>) and above all, the birth of baby Émile! Why have I only included two heart emojis?</p>
<h1>What about your 2017?</h1>
<p>I’ve now read a few awesome posts from other R bloggers, from the top of my head:</p>
<ul>
<li>
<p>Bob Rudis posted an <a rel="nofollow" href="https://rud.is/rpubs/2017-year-in-review/" target="_blank">impressive review of his year</a> on Stack Overflow, Github and Twitter, and even made it reproducible for you to make it with your own data!</p>
</li>
<li>
<p>Mara Averick posted <a rel="nofollow" href="https://maraaverick.rbind.io/2017/12/2017-a-year-in-review/" target="_blank">her top 2 tweets by month</a>. Note of them praises Mara so let’s remind everyone she’s the greatest curator of R content ever, and recently became a tidyverse advocate for RStudio!</p>
</li>
<li>
<p>Thomas Lin Pedersen <a rel="nofollow" href="https://www.data-imaginist.com/2017/looking-back-on-2017/" target="_blank">looked back on his fantastic 2017</a>.</p>
</li>
<li>
<p><a rel="nofollow" href="https://kkulma.github.io/2017-12-29-end-of-year-thoughts/" target="_blank">Kasia’s end of year thoughts</a> include an inspiring description of her journey this year and awesome productivity tips for R bloggers.</p>
</li>
</ul>
<p>What’s your take on your 2017, dear reader? In any case, I wish you a happy New Year!</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.masalmon.eu/2017/12/30/best9of2017/"> Maëlle</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/O_IMeG6XuWM" height="1"></a></div>