R/get_package_db.R

Defines functions package_db_cache_location get_package_db

get_package_db <- function(verbose = FALSE) {
    package_db_cache <- package_db_cache_location()

    if (file.exists(package_db_cache)) {
        if (isTRUE(verbose))
            message("Reading package database from cache")

        db <- readRDS(package_db_cache)
    } else {
        if (isTRUE(verbose))
            message("Downloading package database from CRAN")

        db <- tools::CRAN_package_db()

        if (!dir.exists(dirname(package_db_cache)))
            dir.create(dirname(package_db_cache), recursive = TRUE)

        saveRDS(db, file = package_db_cache, compress = FALSE)
    }

    return(db)
}


package_db_cache_location <- function() {
    file.path(tempdir(), "pkg.deps_cache", "package_db.RDS")
}
robertdj/pkg.deps documentation built on June 25, 2021, 9:51 p.m.