Function to list available archives
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
export(fetch_available_archives)
|
||||
export(fetch_available_packages)
|
||||
export(list_depends)
|
||||
|
||||
46
R/fetch_available_archives.R
Normal file
46
R/fetch_available_archives.R
Normal file
@@ -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()
|
||||
)
|
||||
}
|
||||
19
man/fetch_available_archives.Rd
Normal file
19
man/fetch_available_archives.Rd
Normal file
@@ -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.
|
||||
}
|
||||
Reference in New Issue
Block a user