diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index c13f43bd..43ce1fcd 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -47,5 +47,5 @@ jobs: needs: coverage - name: Test coverage - run: covr::codecov() + run: covr::codecov(function_exclusions='dl_pkgstats_data') shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index 7f743414..dec53ef8 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: pkgstats Title: Metrics of R Packages -Version: 0.0.4.005 +Version: 0.0.4.006 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) @@ -20,7 +20,9 @@ Imports: sys, withr Suggests: + curl, hms, + jsonlite, knitr, parallel, pkgbuild, diff --git a/NAMESPACE b/NAMESPACE index de85469a..88e2f80c 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(ctags_install) export(ctags_test) export(desc_stats) +export(dl_pkgstats_data) export(extract_tarball) export(loc_stats) export(pkgstats) diff --git a/R/pkgstats-data-download.R b/R/pkgstats-data-download.R new file mode 100644 index 00000000..6755cc96 --- /dev/null +++ b/R/pkgstats-data-download.R @@ -0,0 +1,56 @@ +#' Download latest version of 'pkgstats' data +#' +#' @param current If 'FALSE', download data for all CRAN packages ever released, +#' otherwise (default) download data only for current CRAN packages. +#' @param path Local path to download file. +#' @param quiet If `FALSE`, display progress information on screen. +#' @return (Invisibly) A `data.frame` of `pkgstats` results, one row for each +#' package. +#' @family archive +#' @export +dl_pkgstats_data <- function (current = TRUE, + path = tempdir (), + quiet = FALSE) { + + requireNamespace ("curl") + requireNamespace ("jsonlite") + + u <- paste0 ( + "https://api.github.com/repos/", + "ropensci-review-tools/pkgstats/", + "releases/latest" + ) + + res <- curl::curl_fetch_memory (u) + hdrs <- curl::parse_headers (res$headers) + http_code <- as.integer (gsub ( + "^http\\/[0-9]\\s?|\\s+$", + "", + hdrs [1], + ignore.case = TRUE + )) + if (http_code != 200L) { + stop ( + "Call to GitHub failed with http error code [", + http_code, "]" + ) + } + + res <- jsonlite::fromJSON (rawToChar (res$content)) + assets <- res$assets + + i <- ifelse ( + current, + grep ("current", assets$name, ignore.case = TRUE), + grep ("all", assets$name, ignore.case = TRUE) + ) + dl_url <- assets$browser_download_url [i] + f <- file.path (path, basename (dl_url)) + + curl::curl_download (url = dl_url, destfile = f, quiet = quiet) + if (!quiet) { + message ("Downloaded to [", f, "]") + } + + invisible (readRDS (f)) +} diff --git a/codemeta.json b/codemeta.json index f6734d2e..fada86ba 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/pkgstats", "issueTracker": "https://github.com/ropensci-review-tools/pkgstats/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.0.4.005", + "version": "0.0.4.006", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/man/dl_pkgstats_data.Rd b/man/dl_pkgstats_data.Rd new file mode 100644 index 00000000..7c430324 --- /dev/null +++ b/man/dl_pkgstats_data.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkgstats-data-download.R +\name{dl_pkgstats_data} +\alias{dl_pkgstats_data} +\title{Download latest version of 'pkgstats' data} +\usage{ +dl_pkgstats_data(current = TRUE, path = tempdir(), quiet = FALSE) +} +\arguments{ +\item{current}{If 'FALSE', download data for all CRAN packages ever released, +otherwise (default) download data only for current CRAN packages.} + +\item{path}{Local path to download file.} + +\item{quiet}{If \code{FALSE}, display progress information on screen.} +} +\value{ +(Invisibly) A \code{data.frame} of \code{pkgstats} results, one row for each +package. +} +\description{ +Download latest version of 'pkgstats' data +} +\seealso{ +Other archive: +\code{\link{pkgstats_from_archive}()} +} +\concept{archive} diff --git a/man/pkgstats_from_archive.Rd b/man/pkgstats_from_archive.Rd index f26f09f6..ca39f728 100644 --- a/man/pkgstats_from_archive.Rd +++ b/man/pkgstats_from_archive.Rd @@ -65,4 +65,8 @@ Each analysis in an archive trawl spawns several \emph{unsupervised} processes, preventing the trawl from running in parallel. Accurate results can only be guaranteed by running this function as a single process. } +\seealso{ +Other archive: +\code{\link{dl_pkgstats_data}()} +} \concept{archive}