How many downloads does my package have?
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Everyone that authors an R package is curious about how many users download it. As far as I know there’s still no way to get information on all the downloads, from all the R mirrors. Here I’m using package cranlogs, which only gives information on the downloads from the R Studio mirror. It also does not allow to now from where in the world these downloads were made. However, it has a major advantage: speed! The package cranlogs provides a easy (and way faster) method to get this information without having to download all the log files (which can take a long time).
I have written this little script, which I use to keep track of my packages’ downloads (here I’m using MetaLandSim as an example).
First of all let’s load all the required R packages:
#install.packages("cranlogs") library(cranlogs) library(ggplot2)
If we want to know about last week’s downloads:
#Last week's downloads cran_downloads(packages="MetaLandSim", when="last-week") ## date count package ## 1 2019-03-30 7 MetaLandSim ## 2 2019-03-31 7 MetaLandSim ## 3 2019-04-01 11 MetaLandSim ## 4 2019-04-02 30 MetaLandSim ## 5 2019-04-03 30 MetaLandSim ## 6 2019-04-04 19 MetaLandSim ## 7 2019-04-05 11 MetaLandSim
Or about the overall downloads (the last date has to be the previous day):
#How many overall downloads mls <- cran_downloads(packages="MetaLandSim", from = "2014-11-09", to = Sys.Date()-1) sum(mls[,2])
So… the number of downloads MetaLandSim has is…
## [1] 21868
We can now plot the resulting graph, depicting the daily downloads:
#Plot gr0 <- ggplot(mls2, aes(mls2$date, mls2$count)) + geom_line(colour = "red",size=1) gr0 + xlab("Time") + ylab("Nr. of downloads") + labs(title = paste0("MetaLandSim daily downloads ", Sys.Date()-1))
Or we can plot the cumulative downloads sum to get an idea about the rate of increase in download numbers:
#Cumulative cumulative <- cumsum(mls[,2]) mls2 <- cbind(mls,cumulative) #Plot gr1 <- ggplot(mls2, aes(mls2$date, mls2$cumulative)) + geom_line(colour = "blue",size=1) gr1 + xlab("Time") + ylab("Nr. of downloads") + labs(title = paste0("MetaLandSim cumulative downloads until ", Sys.Date()-1))
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.