0

I am trying to insert the current number of CRAN packages and the number of Bioconductor packages to a markdown file.

I have tried this:

length(available.packages(available_packages_filters = c("CRAN")))

I got

[1] 272867

This is different from the number on the CRAN site (16081). Any suggestions would be appreciated.

Zhiqiang Wang
  • 6,206
  • 2
  • 13
  • 27
  • 4
    `available.packages` returns a matrix, you should count number of rows. `nrow(available.packages())` – Ronak Shah Aug 04 '20 at 04:08
  • @RonakShah, It works, thanks a lot. I got the correct number for CRAN. Any ideas about the number of Bioconductor? – Zhiqiang Wang Aug 04 '20 at 04:14
  • 1
    ronak is right; please also be aware that there is likely some noise in this number, as the mirrors are not on a fixed syncing schedule, and the packages that are removed/added will not be reflected perfectly. I believe cran.r-project.org is to be considered the "main" copy. the situation should be similar for bioconductor bit I am less familiar – MichaelChirico Aug 04 '20 at 04:15
  • @MichaelChirico It's good to know. The number obtained on my machine was slightly different from that in RonakShah's answer. That is good enough for my purpose. Thank you. – Zhiqiang Wang Aug 04 '20 at 05:07

1 Answers1

3

available.packages() returns a matrix so you need to use nrow to get number of packages. However, as mentioned by @MichaelChirico note that the number might not be accurate as shown on the CRAN website because of syncing schedules.

CRANpackages <- available.packages()
nrow(CRANpackages)
#[1] 16068

As far as Bioconductor packages are concerned, I am not aware about a function which returns the number of packages but you can get the number from their website using this small scraping script.

library(rvest)
url <- 'https://www.bioconductor.org/packages/release/bioc/'
biocPackages <- url %>% read_html() %>% html_table() %>%.[[1]]
nrow(biocPackages)
#[1] 1905
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213