I'm eager to know,
I think it might reveal some interesting facts.
Edit: bonus points for animated graphics showing the time-evolution of CRAN packages.
To see what packages are installed, use the installed. packages() command. This will return a matrix with a row for each package that has been installed. Below, we look at the first 5 rows of this matrix.
Currently, the CRAN package repository features 18608 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"
here's one shot based on various suggestions.
packages <- available.packages()[,'Package']
ggplot(data.frame(n = nchar(packages))) +
geom_histogram(aes(n), binwidth=1)
all <- length(packages)
## 3168
up <- sum(toupper(packages) == packages)
## 262
low <- sum(tolower(packages) == packages)
## 1697
pie(c(up, low, all-up-low), labels=c("UPPERCASE","lowercase","cAmElCaSe"))
let <- sapply(sapply(letters, grep, tolower(packages)), length)
barplot(let)
length(packages[grep("2$", packages, perl=TRUE)])
# 29
Here is a short piece of code to answer some questions. I will keep adding to my answer when I find time.
library(XML); library(ggplot2);
url = 'http://cran.r-project.org/web/packages/available_packages_by_name.html'
packages = readHTMLTable(url, stringsAsFactors = F)[[1]][-1,]
# histogram of number of characters in package name
qplot(nchar(V1), data = packages)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With