Created
February 21, 2018 22:27
-
-
Save tomhopper/14900d301236799ef4f44d7853efb6e1 to your computer and use it in GitHub Desktop.
Returns a data frame of selected information on all packages on CRAN
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
#' @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