Skip to content

Instantly share code, notes, and snippets.

@nateaff
Created October 10, 2022 00:12
Show Gist options
  • Select an option

  • Save nateaff/7d0e9942395082518137ebb99cac9bf6 to your computer and use it in GitHub Desktop.

Select an option

Save nateaff/7d0e9942395082518137ebb99cac9bf6 to your computer and use it in GitHub Desktop.
Summarize total downloads in the last month of a Cran View
library(cranlogs)
library(ctv)
library(dplyr)
view <- "Optimization"
# Get Cran view packages
views <- ctv::available.views()
packages <- views[[view]]$packagelist
# Split packages in to queries of 20
max_query_num = 20
n_queries = nrow(packages) / max_query_num
name_split <- split(packages$name,
cut(seq_along(packages$core),
n_queries,
labels = FALSE))
# Query cran with a 1 second pause
query_dl <- function(names) {
Sys.sleep(1)
cran_downloads(names, when="last-month")
}
# Query and combine results
dl_response <- lapply(name_split, query_dl)
package_dls <- do.call(rbind, dl_response)
# Sum month's downloads
last_month_dls <-
package_dls %>%
group_by(package) %>%
summarize(total=sum(count)) %>%
arrange(desc(total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment