Reputation: 109864
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.
Upvotes: 6
Views: 642
Reputation: 176648
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
Upvotes: 4
Reputation: 664
I think the somewhat-recently-released package available
by the ROpenSciLabs is designed for this (and much more):
github.com/ropenscilabs/available
Its readme (as of now) lists:
Upvotes: 2
Reputation: 78792
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")
Upvotes: 5