diff --git a/NAMESPACE b/NAMESPACE index 8102891..e0fae85 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,5 @@ # Generated by roxygen2: do not edit by hand +export(fetch_available_archives) export(fetch_available_packages) export(list_depends) diff --git a/R/fetch_available_archives.R b/R/fetch_available_archives.R new file mode 100644 index 0000000..2d4eac9 --- /dev/null +++ b/R/fetch_available_archives.R @@ -0,0 +1,46 @@ +# Requires utils.R + +.fetch_available_archives <- function(refetch) { + check_pacman_dir() + fn <- ".pacman/archive.rds" + if (file.exists(fn)) { + ts <- as.POSIXct("1970-01-01 00:00:00", tz = "GMT") + as.numeric(Sys.Date() + 1) * 86400 + if (refetch || (ts < file.mtime(fn))) { + unlink(fn) + } + } + if (!file.exists(fn)) { + download.file(sprintf("%s/src/contrib/Meta/archive.rds", get_cran_repo()), fn) + } + con <- gzfile(fn, "rb") + on.exit(close(con), add = TRUE) + archive <- readRDS(con) + archive <-lapply(archive, function(pkg) { + packageVersions <- gsub("^([^/]+)/[^_]+_(.+).tar.gz", "\\1%%\\2", rownames(pkg)) + packageVersions <- strsplit(packageVersions, "%%") + packageVersions <- do.call(rbind, packageVersions) + pkg[,c("package","version")] <- packageVersions + sortOrder <- sort(pkg$version, index.return = TRUE)$ix + pkg[sortOrder,c("package", "version")] + }) + archive <- do.call(rbind, archive) + rownames(archive) <- 1:nrow(archive) + return(archive) +} + +#' Fetch the current (or check the cache) list of packages archives available +#' for install from the CRAN repositories. +#' +#' @param refetch Boolean indicating if the local cache should be invalidated. +#' +#' @return A data frame of available package archives and their versions +#' @export +fetch_available_archives <- function(refetch = FALSE) { + tryCatch( + { + .fetch_available_archives(refetch) + }, + warning = function(e) list(), + error = function(e) list() + ) +} \ No newline at end of file diff --git a/man/fetch_available_archives.Rd b/man/fetch_available_archives.Rd new file mode 100644 index 0000000..74123f9 --- /dev/null +++ b/man/fetch_available_archives.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fetch_available_archives.R +\name{fetch_available_archives} +\alias{fetch_available_archives} +\title{Fetch the current (or check the cache) list of packages archives available +for install from the CRAN repositories.} +\usage{ +fetch_available_archives(refetch = FALSE) +} +\arguments{ +\item{refetch}{Boolean indicating if the local cache should be invalidated.} +} +\value{ +A data frame of available package archives and their versions +} +\description{ +Fetch the current (or check the cache) list of packages archives available +for install from the CRAN repositories. +}