ropensci-archive / wishlist

:no_entry: ARCHIVED :no_entry:
https://discuss.ropensci.org/c/wishlist/6
50 stars 4 forks source link

server providing a badge/shield for R package download statistics from the CRAN mirror #14

Closed cboettig closed 9 years ago

cboettig commented 9 years ago

Stealing this suggestion from @jennybc: it would be nice to be able to badge R packages on Github with download statistics, something like:

Looks like it would be straight forward to have service parse the cran logs and compute a simple sum of total downloads by package. (This could be done incrementally by storing the current sums to avoid parsing every single file every time).

It could then generate an svg file with the appropriate data for each package (e.g. using the shields.io api or maybe more simply just based on those svg layouts). A user could then add the shield to the readme using a url based on the package name, e.g.

![](http://path.to.service/packagename.svg)

Maybe there are more elegant ways to do this, but seems simple enough.

Obviously it would be handy to have a slightly more general purpose R package for parsing the logs and computing common statistics by package; e.g. downloads over time etc.

sckott commented 9 years ago

@cboettig can we just use gabor's tool ? e.g.,

http://cranlogs.r-pkg.org/downloads/total/last-week/rfishbase

[
  {
      start: "2015-04-15",
      end: "2015-04-21",
      downloads: 104,
      package: "rfishbase"
  }
]

not sure of the details of his server, if he plans to maintain it going forward, etc.

cboettig commented 9 years ago

@sckott that's perfect, thanks. Maybe we should consider sending a pull request that would provide svg output in addition to the json.

Meanwhile, for packages using .Rmd this is perfect. e.g. we can define a wee function to create the badge using his API:

downloads <- function(package=read.dcf("DESCRIPTION")[1,][["Package"]], from="2012-01-01", to=Sys.Date()){
  data <- httr::content(httr::GET(paste0("http://cranlogs.r-pkg.org/downloads/total/", from, ":", to, "/", package)))
  print(paste0("![](http://shields.io/badge/downloads-",data[[1]]$downloads,"-blue.svg"))
}

downloads()

We can just call that function in a chunk or inline call at the top of the .Rmd to get it embedded into the the markdown output

thanks for the pointer.

karthik commented 9 years ago

Totally forgot that those badges are just svg files. This should be simple to hack together. Yes @sckott it relies o. Gabor to maintain that but I suspect it won't go away anytime soon. I could also rebuild this super quickly with heroku

karthik commented 9 years ago

@cboettig I like the idea of sending a PR to serve the svg directly. I would make it clear that these are RStudio mirror downloads (and not overall, which is unfortunate because others like pypi reflect correct # of downloads).

Otherwise it reflects poorly when some packages numbers are wildly off.

The Rmd suggestion sounds like a bad idea, because that expects one to knit a Rmd every day. Most projects (even most of ropensci's own) are not knitted that frequently, especially for inactive projects.

karthik commented 9 years ago

Also there has got to be a way to prevent GitHub from caching images. It always does and I don't know how Travis forces a refresh when a build fails or passes. Even the url to your initial badge is this:

https://camo.githubusercontent.com/bdb94e7ab1a739930733fbd1b4f087e5b73cd8d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d343533322d626c75652e737667
cboettig commented 9 years ago

@karthik Great points. Looks like cranlogs.app is in javascript so a PR is above my pay grade (I cause enough trouble with my terribly ruby on the fishbaseapi app). I filed the issue linked above, hopefully this is something Gabor can do in his sleep ;-)

Yeah, it's annoying just how crude the download count number is, though I imagine people will tend to benchmark the number against other R packages, which mitigates the issue a bit. All download counts are in some sense underestimates (e.g. pip install misses downloads of the same package by apt-get, or prepackaged in some other distribution system like anaconda or a virtual machine etc). I could go either way.

cboettig commented 9 years ago

Gabor has now implemented this; anyone can add a badge for any package on CRAN using:

![](http://cranlogs-dev.r-pkg.org/badges/<packagename>)

so closing this issue. See his repo for more details and other issues on how to refine this; https://github.com/metacran/cranlogs.app/issues. Thanks @jennybc for a great idea!