-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", , "[email protected]", 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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.