Rating R Packages

Quickly rating some R packages I like with R

Robert McDonnell

2 minute read

The new rOpenSci package packagemetrics is a new ‘meta’ package for R with info on packages: dependencies, how long issues take to be resolved, how many watchers on GitHub, and more. Let’s take a look at a few packages I use and some of my own. Install: install.packages("formattable") devtools::install_github("ropenscilabs/packagemetrics") Then load the packages we’re going to use (I liked the table they have in their README, so I thought I’d keep with that style): library(formattable) library(packagemetrics) library(dplyr) Next, let’s get the packages I’m interested in and make our nice table: packages <- list("dplyr", "tidyr", "tidyRSS", "congressbr", "rstan", "rjags", "electionsBR", "tmap") pd <- purrr::map(packages, combine_metrics) %>% data.table::rbindlist() %>% select(package, published, dl_last_month, stars, forks, last_commit, last_issue_closed, depends_count, watchers) %>% mutate(last_commit = round(last_commit, 1), last_issue_closed = round(last_issue_closed, 1)) pd[is.na(pd)] <- "" formattable(pd, list( package = formatter("span", style = x ~ style(font.weight = "bold")), contributors = color_tile("white","#1CC2E3"), depends_count = color_tile("white", "#1CC2E3"), reverse_count = color_tile("white", "#1CC2E3"), tidyverse_happy = formatter("span", style = x ~ style(color = ifelse(x, "purple","white")), x ~ icontext(ifelse(x, "glass","glass"))), vignette = formatter("span", style = x ~ style(color = ifelse(x, "green","white")), x ~ icontext(ifelse(x, "ok","ok"))), has_tests = formatter("span", style = x ~ style(color = ifelse(x, "green","red")), x ~ icontext(ifelse(x, "ok","remove"))), dl_last_month = color_bar("#56A33E"), forks = color_tile("white", "#56A33E"), stars = color_tile("white", "#56A33E"), last_commit = color_tile("#F06B13","white", na.rm=T), last_issue_closed = color_tile("#F06B13","white", na.rm=T) )) package published dl_last_month stars forks last_commit last_issue_closed depends_count watchers dplyr 2016-06-24 295115 1847 728 0.2 0 1 219 tidyr 2017-05-15 147418 469 168 0.2 0 1 58 tidyRSS 2017-03-01 319 10 2 0.4 0.7 1 3 congressbr 2017-04-30 556 1 rstan 2017-04-19 9583 341 132 0.1 0.1 3 66 rjags 2016-02-19 12638 2 electionsBR 2016-12-13 664 17 4 0.7 3.6 1 7 tmap 2017-05-11 4236 144 25 0 0.1 2 16 Nice table.

Robert McDonnell

3 minute read

After seeing Nadieh Bremer’s great Breathing Earth infographic, I thought it would be cool to recreate it in R, as you do. Then I saw that it was made from lots of tif files…hmmm. I did some work with those before, ain’t doin it again voluntarily, no thanks. So then I started thinking about something else that would be (kind of) similar and interesting. I saw the sf package and its interesting geom_sf() recently, and so I thought it would be a nice opportunity to try that out.

UK Elections 2017

A quick look at the UK 2017 election results with R

Robert McDonnell

1 minute read

This post is a quickie to show how we can visualize the UK election results with just a few lines of R code. (Really, very few). 1 We can load in our usual tidyverse tools, along with a handy little data package, parlitools. library(readr) library(dplyr) library(ggplot2) library(parlitools) library(sf) Thanks to this R Bloggers post, we have the data (the UK Electoral Commission must have it up by now anyway), so

Human Capital Index Maps

Mapping the Human Capital Index Various Ways in R

Robert McDonnell

3 minute read

I’m not too sure that the Human Capital Index is a reliable measure of what it’s supposed to measure, but I’m convinced by Deirdre McCloskey’s eloquent arguments that it is Human Capital, or ingenuity, in less dry terms, that has made the modern world (in conjunction with freedom and some basic legal structures). However, all that interesting talk aside, there are now quite a few new ways to make maps in R.

CausalImpact & Healthcare Costs in the US

A quick look at the CausalImpact package in R, studying US healthcare costs over time

Robert Myles MCDonnell

4 minute read

This article by Mike Holly on Mises.org interested me. I wasn’t aware of the history of healthcare costs in the US, and it’s quite surprising, especially the take-off in costs after the 1960s. Holly’s argument is that the “U.S. ‘health care cost crisis’ didn’t start until 1965. The government increased demand with the passage of Medicare and Medicaid while restricting the supply of doctors and hospitals.” In fact, I was quite impressed with this graph: x <- c("rvest", "dplyr", "tidyr", "ggplot2", "magrittr", "lubridate") lapply(x, require, character.only = TRUE) I’ve wanted an excuse to use Google’s CausalImpact package for a while now, so let’s give it a shot using these data.

Robert McDonnell

3 minute read

From time to time, you might need to copy and paste something into R and turn it into a character string. Maybe it’s something from the output of an error message, or from someone else’s malformed data, or something copied from a document or the internet. If it’s something small, then it’s usually OK to just manually insert "" around the strings and , between them. For something large, that’s just a nightmare.

Update R from inside R

How to quickly update R from inside R itself

Robert McDonnell

1 minute read

I was just about to update R a while ago when I thought to myself that there must be a way to do this inside of R (RStudio, I mean). A quick Google search brought me to the installr package. Very nice, but I use a Mac. Hmmm… A bit more searching and I found Andrea Cirillo’s updateR package, which was made for OS X, fantastic. I tried it out, and although it worked great, I still had to leave RStudio to check to see if the latest version installed.

Robert McDonnell

4 minute read

This week I was working with some RSS feeds in R. You can parse these feeds directly with packages like XML or xml2, or use the rss package (not on CRAN) or the feedeR package (on CRAN). However, I noticed that both rss and feedeR return lists, which necessitates further work in R to get the data into a tidy format, and that both packages leave interesting data behind. With that in mind, I decided to make tidyRSS, a package for parsing these feeds and returning a tidy data frame to the user.

3 minute read

Brazil, where I live, has a shockingly high murder rate. I mean, it’s freaking astounding. A recent blog I read (see it here) caused a bit of discussion among some friends of mine on facebook. Is Brazil a failed state? The obvious answer seems ‘no’, but then again, isn’t security one of the basic functions of the state? Just how bad is it with regard to murders in Brazil? (Pretty nuts is the answer.) We can visualize this is in R to get some idea of how nuts it is.

8 minute read

I really like this image by Tom Burns.1 The liberal2 in me appreciates making cheap fun of people who were horribly mistaken (Lenin; Marx, although I don’t mean to slight his contributions to social science), scum like Stalin, and Fidel Castro, who might have started out with a laudable takedown of a corrupt dictator, but who then became…a corrupt dictator, of course. The artist in me just loves the awesome colours.