library(testthat)

Get number of packages on CRAN at a given date

#' Get number of packages on CRAN at a given date
#' 
#' Query MRAN to Get number of packages on CRAN at a given date.
#' MRAN -> Microsoft snapshots of CRAN.
#'
#' @param date A character string representing a date of the form yyyy-mm-dd.
#'
#' @return A data.frame with 2 columns `date` and `n` the number of packages on CRAN
#' at that date.
#' 
#' @export
#' @importFrom utils available.packages 
#' 
#' @examples
cranology <- function(date) {
  data.frame(
    date = date,
    n = nrow(
      available.packages(
        repos = sprintf("https://mran.microsoft.com/snapshot/%s", date)
      )
    )
  )
}
cranology("2020-03-15")
test_that("cranology works", {
  result <- cranology("2020-03-15")
  # generated with dput()
  expected_df <- structure(
    list(date = "2020-03-15", n = 15367L),
    class = "data.frame",
    row.names = c(NA, -1L)
  )
  expect_equal(result, expected_df)
})
# Run but keep eval=FALSE to avoid infinite loop
# Execute in the console directly
fusen::inflate(
  flat_file = "dev/flat_minimal.Rmd", 
  open_vignette = FALSE,
  check = FALSE,
  vignette_name = NA
)


ALanguillaume/cranology documentation built on April 21, 2022, 12:32 a.m.