Permalink
Please sign in to comment.
Showing
with
151 additions
and 27 deletions.
- +1 −0 .Rbuildignore
- +1 −3 .gitignore
- +12 −7 DESCRIPTION
- +2 −0 LICENSE
- +6 −1 NAMESPACE
- +71 −0 R/cranlogs.R
- +0 −16 cranlogs.Rproj
- +48 −0 man/cran_downloads.Rd
- +10 −0 man/cranlogs.Rd
| @@ -0,0 +1 @@ | ||
| +^tags$ |
| @@ -1,3 +1 @@ | ||
| -.Rproj.user | ||
| -.Rhistory | ||
| -.RData | ||
| +/tags |
19
DESCRIPTION
| @@ -1,8 +1,13 @@ | ||
| Package: cranlogs | ||
| -Title: What the package does (one line) | ||
| -Version: 0.1 | ||
| -Authors@R: "First Last <first.last@example.com> [aut, cre]" | ||
| -Description: What the package does (one paragraph) | ||
| -Depends: R (>= 3.1.1) | ||
| -License: What license is it under? | ||
| -LazyData: true | ||
| +Title: Download Logs from the RStudio CRAN Mirror | ||
| +Version: 1.0.0 | ||
| +Authors@R: "Gabor Csardi <csardi.gabor@gmail.com> [aut, cre]" | ||
| +Description: API to the database of CRAN package downloads from the RStudio | ||
| + CRAN mirror. The database itself is at http://cranlogs.r-pkg.org, see | ||
| + https://github.com/metacran/cranlogs.app for the raw API. | ||
| +License: MIT + file LICENSE | ||
| +URL: https://github.com/metacran/cranlogs | ||
| +BugReports: https://github.com/metacran/cranlogs/issues | ||
| +Imports: | ||
| + httr, | ||
| + jsonlite |
| @@ -1 +1,6 @@ | ||
| -exportPattern("^[^\\.]") | ||
| +# Generated by roxygen2 (4.0.2): do not edit by hand | ||
| + | ||
| +export(cran_downloads) | ||
| +importFrom(httr,GET) | ||
| +importFrom(httr,content) | ||
| +importFrom(jsonlite,fromJSON) |
71
R/cranlogs.R
| @@ -0,0 +1,71 @@ | ||
| + | ||
| +#' Download Logs from the RStudio CRAN Mirror | ||
| +#' | ||
| +#' @docType package | ||
| +#' @name cranlogs | ||
| +#' @importFrom httr GET | ||
| +#' @importFrom httr content | ||
| +#' @importFrom jsonlite fromJSON | ||
| +NULL | ||
| + | ||
| +url <- "http://cranlogs.r-pkg.org/downloads/daily/" | ||
| + | ||
| +#' Daily package downloads from the RStudio CRAN mirror | ||
| +#' | ||
| +#' @param package A package to query, or \code{NULL} for a sum of | ||
| +#' downloads for all packages. | ||
| +#' @param when \code{last_day}, \code{last_week} or \code{last_month}. | ||
| +#' If this is given, then \code{from} and \code{to} are ignored. | ||
| +#' @param from Start date, in \code{yyyy-mm-dd} format, or | ||
| +#' \code{yesterday}. It is ignored if \code{when} is given. | ||
| +#' @param to End date, in \code{yyyy-mm-dd} format, or | ||
| +#' \code{yesterday}. It is ignored if \code{when} is given. | ||
| +#' @return A list with entries: \itemize{ | ||
| +#' \item \code{downloads} The downloads, in a two-column data frame: | ||
| +#' date and download count. | ||
| +#' \item \code{start} Start date. | ||
| +#' \item \code{end} End date. | ||
| +#' \item \code{package} The queried package. This entry is missing | ||
| +#' if the total number of downloads for all packages was queried. | ||
| +#' } | ||
| +#' | ||
| +#' @export | ||
| +#' @examples | ||
| +#' | ||
| +#' ## All downloads yesterday | ||
| +#' cran_downloads() | ||
| +#' | ||
| +#' ## All downloads for 'dplyr' yesterday | ||
| +#' cran_downloads(package = "dplyr") | ||
| +#' | ||
| +#' ## Daily downloads for 'igraph' last week | ||
| +#' cran_downloads(package = "igraph", when = "last-week") | ||
| +#' | ||
| +#' ## Downloads in the specified time interval | ||
| +#' cran_downloads(from = "2014-06-30", to = "2014-08-08") | ||
| + | ||
| +cran_downloads <- function(package = NULL, | ||
| + when = c("last-day", "last-week", "last-month"), | ||
| + from = "last-day", to = "last-day") { | ||
| + | ||
| + if (!missing(when)) { | ||
| + interval <- match.arg(when) | ||
| + } else { | ||
| + if (from == to) { | ||
| + interval <- from | ||
| + } else { | ||
| + interval <- paste(from, sep = ":", to) | ||
| + } | ||
| + } | ||
| + | ||
| + if (is.null(package)) { | ||
| + package <- "" | ||
| + } else { | ||
| + package <- paste0("/", package) | ||
| + } | ||
| + | ||
| + r <- fromJSON(content(GET(paste0(url, interval, package)), as = "text")) | ||
| + class(r) <- "cranlogs" | ||
| + r | ||
| + | ||
| +} |
| @@ -1,16 +0,0 @@ | ||
| -Version: 1.0 | ||
| - | ||
| -RestoreWorkspace: No | ||
| -SaveWorkspace: No | ||
| -AlwaysSaveHistory: Default | ||
| - | ||
| -EnableCodeIndexing: Yes | ||
| -Encoding: UTF-8 | ||
| - | ||
| -AutoAppendNewline: Yes | ||
| -StripTrailingWhitespace: Yes | ||
| - | ||
| -BuildType: Package | ||
| -PackageUseDevtools: Yes | ||
| -PackageInstallArgs: --no-multiarch --with-keep.source | ||
| -PackageRoxygenize: rd,collate,namespace |
| @@ -0,0 +1,48 @@ | ||
| +% Generated by roxygen2 (4.0.2): do not edit by hand | ||
| +\name{cran_downloads} | ||
| +\alias{cran_downloads} | ||
| +\title{Daily package downloads from the RStudio CRAN mirror} | ||
| +\usage{ | ||
| +cran_downloads(package = NULL, when = c("last-day", "last-week", | ||
| + "last-month"), from = "last-day", to = "last-day") | ||
| +} | ||
| +\arguments{ | ||
| +\item{package}{A package to query, or \code{NULL} for a sum of | ||
| +downloads for all packages.} | ||
| + | ||
| +\item{when}{\code{last_day}, \code{last_week} or \code{last_month}. | ||
| +If this is given, then \code{from} and \code{to} are ignored.} | ||
| + | ||
| +\item{from}{Start date, in \code{yyyy-mm-dd} format, or | ||
| +\code{yesterday}. It is ignored if \code{when} is given.} | ||
| + | ||
| +\item{to}{End date, in \code{yyyy-mm-dd} format, or | ||
| +\code{yesterday}. It is ignored if \code{when} is given.} | ||
| +} | ||
| +\value{ | ||
| +A list with entries: \itemize{ | ||
| + \item \code{downloads} The downloads, in a two-column data frame: | ||
| + date and download count. | ||
| + \item \code{start} Start date. | ||
| + \item \code{end} End date. | ||
| + \item \code{package} The queried package. This entry is missing | ||
| + if the total number of downloads for all packages was queried. | ||
| +} | ||
| +} | ||
| +\description{ | ||
| +Daily package downloads from the RStudio CRAN mirror | ||
| +} | ||
| +\examples{ | ||
| +## All downloads yesterday | ||
| +cran_downloads() | ||
| + | ||
| +## All downloads for 'dplyr' yesterday | ||
| +cran_downloads(package = "dplyr") | ||
| + | ||
| +## Daily downloads for 'igraph' last week | ||
| +cran_downloads(package = "igraph", when = "last-week") | ||
| + | ||
| +## Downloads in the specified time interval | ||
| +cran_downloads(from = "2014-06-30", to = "2014-08-08") | ||
| +} | ||
| + |
| @@ -0,0 +1,10 @@ | ||
| +% Generated by roxygen2 (4.0.2): do not edit by hand | ||
| +\docType{package} | ||
| +\name{cranlogs} | ||
| +\alias{cranlogs} | ||
| +\alias{cranlogs-package} | ||
| +\title{Download Logs from the RStudio CRAN Mirror} | ||
| +\description{ | ||
| +Download Logs from the RStudio CRAN Mirror | ||
| +} | ||
| + |
0 comments on commit
b7335a7