Skip to content

Instantly share code, notes, and snippets.

@tomhopper
Created February 21, 2018 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhopper/14900d301236799ef4f44d7853efb6e1 to your computer and use it in GitHub Desktop.
Save tomhopper/14900d301236799ef4f44d7853efb6e1 to your computer and use it in GitHub Desktop.
Returns a data frame of selected information on all packages on CRAN
#' @description Returns a list of all packages on CRAN
#' @param columns_list A character vector of field names to return from package DESCRIPTION files
#' @return A data frame containing all packages on CRAN
#' @details Function modified from StackOverflow answer at \url{https://stackoverflow.com/a/11561793}.
#' @importFrom magrittr %>%
#' @importFrom tibble as.tibble
#' @importFrom dplyr select_
getCRANPackages <- function(columns_list = c("Package", "Title", "Version", "Date", "Published", "URL")) {
contrib.url(getOption("repos")["CRAN"], "source")
description <- sprintf("%s/web/packages/packages.rds",
getOption("repos")["CRAN"])
con <- if(substring(description, 1L, 7L) == "file://") {
file(description, "rb")
} else {
url(description, "rb")
}
on.exit(close(con))
db <- readRDS(gzcon(con))
rownames(db) <- NULL
db <- db %>% as.tibble() %>%
select_(.dots = columns_list)
return(db)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment