搜索特定作者的包

时间:2012-04-10 01:05:37

标签: r r-package

有时我习惯于特定R包的设计,并且想要在CRAN中搜索该作者的所有包(例如,让我们使用Hadley Wickham)。我怎么能进行这样的搜索(我想使用R但是这不一定是搜索模式)?

3 个答案:

答案 0 :(得分:11)

Crantastic can search by author。你可以用crantastic做更多的事情但是你已经提供了你正在寻找的功能。

答案 1 :(得分:11)

不完全是作者,但也许维护人员访问也会有用吗?

http://cran.r-project.org/web/checks/check_summary_by_maintainer.html#summary_by_maintainer

由Tyler Rinker编辑

使用这些代码行可以实现DWin的建议:

search.lib <- function(term, column = 1){
    require(XML)
    URL <- "http://cran.r-project.org/web/checks/check_summary_by_maintainer.html#summary_by_maintainer"
    dat <-readHTMLTable(doc=URL, which=1, header=T, as.is=FALSE)
    names(dat) <- trimws(names(dat))
    dat$Maintainer[dat$Maintainer == ""] <- NA
    dat$Maintainer = zoo::na.locf(dat$Maintainer)
    if (is.numeric(column)) {
        dat[agrep(term, dat[, column]), 1:3]
    } else {
        dat[agrep(term, dat[, agrep(column, colnames(dat))]), 1:3]
    }
}

search.lib("hadley")
search.lib("bolker")
search.lib("brewer", 2)

答案 2 :(得分:9)

改编自available.packages by publication date

## restrict to first 100 packages (by alphabetical order)
pkgs <- unname(available.packages()[, 1])[1:100]
desc_urls <- paste(options("repos")$repos,"/web/packages/", pkgs, 
    "/DESCRIPTION", sep = "")
desc <- lapply(desc_urls, function(x) read.dcf(url(x)))
authors <- sapply(desc, function(x) x[, "Author"])

因为我是一个自恋者(而且Hadley Wickham在前100名中没有包[[strong>这在2012年是真的,但现在不可能是真的,在2018年!]):

pkgs[grep("Bolker",authors)]
# [1] "ape"

这个解决方案的主要问题是真正做到这一点(而不仅仅是前100个包)意味着要在包装信息上花费3000多次CRAN ......

编辑:一个更好的解决方案,基于Jeroen Oom在同一个地方的解决方案:

recent.packages.rds <- function(){
    mytemp <- tempfile()
    download.file(paste0(options("repos")$repos,"/web/packages/packages.rds"),
                  mytemp)
    mydata <- as.data.frame(readRDS(mytemp), row.names=NA)
    mydata$Published <- as.Date(mydata[["Published"]])
    mydata
}

mydata <- recent.packages.rds()
unname(as.character(mydata$Package[grep("Wickham",mydata$Author)]))
# [1] "classifly"    "clusterfly"   "devtools"     "evaluate"     "fda"         
# [6] "geozoo"       "ggmap"        "ggplot2"      "helpr"        "hints"       
# [11] "HistData"     "hof"          "itertools"    "lubridate"    "meifly"      
# [16] "memoise"      "munsell"      "mutatr"       "normwhn.test" "plotrix"     
# [21] "plumbr"       "plyr"         "productplots" "profr"        "Rd2roxygen"  
# [26] "reshape"      "reshape2"     "rggobi"       "roxygen"      "roxygen2"    
# [31] "scales"       "sinartra"     "stringr"      "testthat"     "tourr"       
# [36] "tourrGui"