Determine number of versions in history of R package on CRAN

爱⌒轻易说出口 提交于 2019-12-23 10:47:07

问题


Is it possible to determine the number of versions a package on CRAN has had in the past?


回答1:


Here's one using the XML package. This just counts the archived versions (more precisely, the number of archived tar.gz files). Add 1 to get the total number of versions, including the current.

nCRANArchived <- function(pkg) {
    link <- paste0("http://cran.r-project.org/src/contrib/Archive/", pkg)
    qry <- XML::getHTMLLinks(link, xpQuery = "//@href[contains(., 'tar.gz')]")
    length(qry)
}

nCRANArchived("data.table")
# [1] 33
nCRANArchived("ggplot2")
# [1] 28
nCRANArchived("MASS")
# [1] 40
nCRANArchived("retrosheet") ## shameless plug
# [1] 2



回答2:


Here's a simple function that goes to the CRAN page with the old versions of a given package and counts them.

num.versions = function(package) {

  require(rvest)
  require(stringr)

  # Get text of web page with package version info
  page = read_html(paste0("https://cran.r-project.org/src/contrib/Archive/", package, "/"))
  doc  = html_text(page)

  # Return number of versions (add 1 for current version)
  paste("Number of versions: ", 
        length(unlist(str_extract_all(doc, "tar\\.gz"))) + 1)

}

num.versions("ggplot2")
[1] "Number of versions:  29"

num.versions("data.table")
[1] "Number of versions:  34"

num.versions("distcomp")
[1] "Number of versions:  4"


来源:https://stackoverflow.com/questions/37367649/determine-number-of-versions-in-history-of-r-package-on-cran

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!