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