Skip to content

Instantly share code, notes, and snippets.

@tomhopper
Created February 21, 2018 22:27
Show Gist options
  • Select an option

  • Save tomhopper/14900d301236799ef4f44d7853efb6e1 to your computer and use it in GitHub Desktop.

Select an option

Save tomhopper/14900d301236799ef4f44d7853efb6e1 to your computer and use it in GitHub Desktop.

Revisions

  1. tomhopper created this gist Feb 21, 2018.
    24 changes: 24 additions & 0 deletions getCRANPackages.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #' @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)
    }