How can one check of a package has been archived from CRAN. One can check if a package is a CRAN package like so:
"ggplot2" %in% available.packages()[,1]
## [1] TRUE
But a package like helpr shows false with the same code. How could I check if a name is archived?
"helpr" %in% available.packages()[,1]
## [1] FALSE
I could scrape the archive like this:
archs <- XML::readHTMLTable(readLines("https://cran.r-project.org/src/contrib/Archive/"),
stringsAsFactors = FALSE)
gsub("/$", "", na.omit(archs[[1]][, "Name"]))
but I assume there is a built in base way to to do this as using an archived package name will throw a warning in a CRAN check.
Currently, the CRAN package repository features 18506 available packages.
The way forward is to download the tarball, install all package dependencies and then install the package from the local downloaded file. Note: This will only work if you have the build tools installed on your machine. On Linux this will be the case.
*Actually, as of this writing, there are 9,999 packages on CRAN.
R packages are a collection of R functions, complied code and sample data. They are stored under a directory called "library" in the R environment. By default, R installs a set of packages during installation.
FWIW, rolling your own CRAN_archive_db
would be something like:
download.file("https://cran.rstudio.com/src/contrib/Meta/archive.rds",
"archive.rds")
archive <- readRDS("archive.rds")
R CMD check
basically calls tools:::.check_packages
. The functionality you're looking for is in tools:::.check_package_CRAN_incoming
, and tools:::CRAN_archive_db
.
Edit (by Tyler Rinker) Using Josh's answer the following code gives me what I'm after though less well succint than @hrbrmstr's:
get_archived <- function(cran = getOption("repos")){
if (is.null(cran)) cran <- "http://cran.rstudio.com/"
con <- gzcon(url(sprintf("%s/%s", cran, "src/contrib/Meta/archive.rds"), open = "rb"))
on.exit(close(con))
x <- readRDS(con)
names(x)
}
check_archived <- function(package){
tolower(package) %in% tolower(get_archived())
}
check_archived("ggplot2")
check_archived("helpr")
check_archived("foo")
## > check_archived("ggplot2")
## [1] TRUE
## > check_archived("helpr")
## [1] TRUE
## > check_archived("foo")
## [1] FALSE
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