Last active
October 2, 2018 15:18
-
-
Save hadley/39ff26495b03744117974e8af0f26c71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
url1 <- "https://cran.rstudio.com/src/contrib/Meta/archive.rds" | |
url2 <- "https://cran.rstudio.com/src/contrib/Meta/current.rds" | |
if (!file.exists(basename(url1))) download.file(url1, basename(url1), quiet = TRUE) | |
if (!file.exists(basename(url2))) download.file(url2, basename(url2), quiet = TRUE) | |
archive <- readRDS("archive.rds") | |
current <- readRDS("current.rds") | |
archive_df <- archive %>% | |
bind_rows(.id = "package") %>% | |
bind_rows(rownames_to_column(current, "package")) | |
as_tibble() | |
daily <- archive_df %>% | |
mutate(submitted = floor_date(mtime, "week")) %>% | |
count(submitted) %>% | |
mutate( | |
year = year(submitted), | |
date = update(submitted, year = 2000) | |
) | |
daily %>% | |
filter(submitted > ymd("2017-01-01")) | |
daily %>% | |
filter(submitted > ymd("2005-01-01"), n < 5) | |
daily %>% | |
filter(submitted > ymd("2010-01-01"), n < 400) %>% | |
ggplot(aes(date, n)) + | |
geom_line() + | |
geom_point() + | |
facet_wrap(~year) + | |
scale_x_datetime(date_labels = "%b") + | |
labs(x = NULL, y = "Weekly downloads") | |
ggsave("accepted-cran.png", width = 8, height = 6, dpi = "screen") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do lines 31/32 do anything or are they just debug remnants from testing with
n<5
(whatevern
is)? And should line 15 pipe intoas_tibble()
, otherwise line 16 does nothing. I guess it gets miraculously transformed to a tibble at some other point, or the rest of the code is happy as a data frame.