문제

Sometimes I get accustomed to a particular R package's design and want to search CRAN for all packages by that author (let's use Hadley Wickham for instance). How can I do such a search (I'd like to use R but this doesn't have to be the mode of search)?

도움이 되었습니까?

해결책

Crantastic can search by author. You can do quite a bit more with crantastic but the functionality you're looking for is already provided there.

다른 팁

Not exactly by author but perhaps access by maintainer would also be useful?

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

EDIT by Tyler Rinker

DWin's suggestion can be brought to fruition with these lines of code:

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)

Adapted from 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"])

Since I'm a narcissist (and Hadley Wickham has no packages in the first 100 [this was true in 2012 but cannot possibly be true now, in 2018!]):

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

The main problem with this solution is that doing it for real (rather than just for the first 100 packages) means hitting CRAN 3000+ times for the package information ...

edit: a better solution, based on Jeroen Oom's solution in the same place:

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"  
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top