List and Description of All Packages in Cran from Within R

List and description of all packages in CRAN from within R

Edit of an almost ten-year old accepted answer. What you likely want is not to scrape (unless you want to practice scraping) but use an existing interface: tools::CRAN_package_db(). Example:

> db <- tools::CRAN_package_db()[, c("Package", "Description")]
> dim(db)
[1] 18978 2
>

The function brings (currently) 66 columns back of which the of interest here are a part.


I actually think you want "Package" and "Title" as the "Description" can run to several lines. So here is the former, just put "Description" in the final subset if you really want "Description":

R> ## from http://developer.r-project.org/CRAN/Scripts/depends.R and adapted
R>
R> require("tools")
R>
R> getPackagesWithTitle <- function() {
+ 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[, c("Package", "Title")]
+ }
R>
R>
R> head(getPackagesWithTitle()) # I shortened one Title here...
Package Title
[1,] "abc" "Tools for Approximate Bayesian Computation (ABC)"
[2,] "abcdeFBA" "ABCDE_FBA: A-Biologist-Can-Do-Everything of Flux ..."
[3,] "abd" "The Analysis of Biological Data"
[4,] "abind" "Combine multi-dimensional arrays"
[5,] "abn" "Data Modelling with Additive Bayesian Networks"
[6,] "AcceptanceSampling" "Creation and evaluation of Acceptance Sampling Plans"
R>

List of all functions in all packages on CRAN?

library(collidr)

# This data.frame is ~300k rows, here are the first 10

collidr::CRANdf[1:10, ]

# package_names function_names
# 1 A3 A3-package
# 2 A3 a3
# 3 A3 a3.base
# 4 A3 a3.gen.default
# 5 A3 a3.lm
# 6 A3 a3.r2
# 7 A3 housing
# 8 A3 multifunctionality
# 9 A3 plot.A3
# 10 A3 plotPredictions
...

list all functions on CRAN

You can use the sos package, for example:

library(sos)
findFn("adply")

The output is an html including links to online documentation packages.

Is there a command in R to view all the functions present in a package?

You can use lsf.str.

For instance:

lsf.str("package:dplyr")

To list all objects in the package use ls

ls("package:dplyr")

Note that the package must be attached.

To see the list of currently loaded packages use

search()

Alternatively calling the help would also do, even if the package is not attached:

help(package = dplyr)

Finally, you can use RStudio which provides an autocomplete function. So, for instance, typing dplyr:: in the console or while editing a file will result in a popup list of all dplyr functions/objects.

How can I extract the names of all package authors from CRAN

Taken from reverse_dependencies_with_maintainers, which was available at one point on the R developer site (I don't see it there now):

  description <- sprintf("%s/web/packages/packages.rds",
getOption("repos")["CRAN"])
con <- if(substring(description, 1L, 7L) == "file://") {
file(description, "rb")
} else {
url(description, "rb")
}
db <- as.data.frame(readRDS(gzcon(con)),stringsAsFactors=FALSE)
close(con)
rownames(db) <- NULL

head(db$Author)
head(db$"Authors@R")

Where Authors@R exists it might be parseable into something better using dget()

getAuthor <- function(x){
if(is.na(x)) return(NA)
a <- textConnection(x)
on.exit(close(a))
dget(a)
}
authors <- lapply(db$"Authors@R", getAuthor)
head(authors)

[[1]]
[1] NA

[[2]]
[1] "Gaurav Sood <gsood07@gmail.com> [aut, cre]"

[[3]]
[1] "Csillery Katalin <kati.csillery@gmail.com> [aut]"
[2] "Lemaire Louisiane [aut]"
[3] "Francois Olivier [aut]"
[4] "Blum Michael <michael.blum@imag.fr> [aut, cre]"

[[4]]
[1] NA

[[5]]
[1] "Csillery Katalin <kati.csillery@gmail.com> [aut]"
[2] "Lemaire Louisiane [aut]"
[3] "Francois Olivier [aut]"
[4] "Blum Michael <michael.blum@imag.fr> [aut, cre]"

[[6]]
[1] NA

List of all packages available on Bioconductor

You can have the list of packages with :

BiocManager::available()

Don't forget to install the package (install.packages("BiocManager"))

Names of R's available packages

A better way than scraping a web page to get the names of packages is to use the available.packages() function and process those results. available.packages() returns a matrix contains details of all packages available (but is filtered by default — see the Details section of ?available.packages for more).

pkgs <- available.packages(filters = "duplicates")
nameCount <- unname(nchar(pkgs[, "Package"]))
table(nameCount)

> table(nameCount)
nameCount
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
32 311 374 360 434 445 368 277 199 132 99 56 56 43 22 19 18 2 12 8
22 24 25 31
5 2 1 1

Using nameCount we can select packages with names containing any number of characters without needing to resort to regexp etc:

> unname(pkgs[which(nameCount == 2), "Package"])
[1] "BB" "bs" "ca" "cg" "dr" "ez" "FD" "ff" "HH" "HI" "iv" "JM" "ks" "M3" "mi"
[16] "np" "oc" "oz" "PK" "PP" "qp" "QT" "RC" "rv" "Rz" "sm" "sn" "sp" "st" "SV"
[31] "tm" "wq"


Related Topics



Leave a reply



Submit