My

Like in 2017 I tweeted too much and therefore was unable to rely onrtweet::get_timeline() (or rtweet::get_my_timeline()) to download mytweets so I exported data via the Tweets tab ofhttps://analytics.twitter.com/. Last year, I downloaded one file perquarter but somehow had to download one per month this time. It wasmonotonous but not horrible.

1
2
3
4
5
6
library("magrittr")

dir("data", full.names = TRUE) %>%
 purrr::map_df(readr::read_csv) %>%
 unique() -> my_tweets

4196 tweets!

Similarly to my 2017 post, I chose the number of likes as criterion todefine my best tweets.

1
2
3
4
5
my_tweets <- dplyr::arrange(my_tweets, - likes)
my_tweets <- janitor::clean_names(my_tweets)

knitr::kable(my_tweets[1:9, "likes"])

likes
162
151
128
112
95
94
91
86
75
1
2
best9 <- my_tweets$tweet_permalink[1:9]

The table above shows that my best tweets were not extremely popular.

My 2017 blog post inspired Bob Rudis to contribute a tweet_shot()function to rtweet, relying on the webshot package, so that’s what Iused.

1
2
3
4
5
6
7
8
9
10
11
shot <- function(permalink){
 rtweet::tweet_shot(permalink) %>%
 magick::image_crop(magick::geometry_area(width = 517,
 height = 517,
 y_off = 88)) %>%
 magick::image_border("salmon", "20x20")
}

images <- purrr::map(as.character(best9),
 shot)

I improved the collage code with two tweaks:

I created rows then columns instead of the other way round, becausethat’s what Instagram does. I did not pay attention to this lastyear but Andrew Caines told me this in a comment.

I did not save the intermediary images to disk. I’ve upped mymagick game!

1
2
3
4
5
6
7
8
9
10
11
12
make_row <- function(i, images){
 images[((i-1)*3+1):((i-1)*3+3)] %>%
 magick::image_join() %>%
 magick::image_append()
}

purrr::map(1:3, make_row,
 images = images) %>%
 magick::image_join() %>%
 magick::image_append(stack = TRUE) %>%
 magick::image_border("salmon", "20x20")

Worth noting from my R year are, according to these tweets,

What about your R year, on Twitter and elsewhere? Have a good last daysof 2018, and a happy 2019!

Related