diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..c97aa07 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1 @@ +^tags$ diff --git a/.gitignore b/.gitignore index 807ea25..61ffc7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -.Rproj.user -.Rhistory -.RData +/tags diff --git a/DESCRIPTION b/DESCRIPTION index a9486ce..31b7bfb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,13 @@ Package: cranlogs -Title: What the package does (one line) -Version: 0.1 -Authors@R: "First Last [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 [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 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..00834d3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2014 +COPYRIGHT HOLDER: Gabor Csardi diff --git a/NAMESPACE b/NAMESPACE index 9c9f9ac..631bc42 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/cranlogs.R b/R/cranlogs.R new file mode 100644 index 0000000..0ef24c6 --- /dev/null +++ b/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 + +} diff --git a/cranlogs.Rproj b/cranlogs.Rproj deleted file mode 100644 index d848a9f..0000000 --- a/cranlogs.Rproj +++ /dev/null @@ -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 diff --git a/man/cran_downloads.Rd b/man/cran_downloads.Rd new file mode 100644 index 0000000..af6b0a5 --- /dev/null +++ b/man/cran_downloads.Rd @@ -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") +} + diff --git a/man/cranlogs.Rd b/man/cranlogs.Rd new file mode 100644 index 0000000..d9e8338 --- /dev/null +++ b/man/cranlogs.Rd @@ -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 +} +