depends.R 1.33 KB
Newer Older
Julien Veyssier's avatar
Julien Veyssier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
old <- getOption("defaultPackages"); r <- getOption("repos")
r["CRAN"] <- "http://cran.irsn.fr/"
options(defaultPackages = c(old, "MASS"), repos = r)
require("tools")

reverse_dependencies_with_maintainers <-
function(packages, which = c("Depends", "Imports", "LinkingTo"),
         recursive = FALSE)
{
    contrib.url(getOption("repos")["CRAN"], "source") # trigger chooseCRANmirror() if required
    description <- sprintf("%s/web/packages/packages.rds",
                           getOption("repos")["CRAN"])
    con <- if(substring(description, 1L, 7L) == "file://")
        file(description, "rb")
    else
        url(description, "rb")
    on.exit(close(con))
    db <- readRDS(gzcon(con))
    rownames(db) <- NULL

    rdepends <- package_dependencies(packages, db, which,
                                     recursive = recursive,
                                     reverse = TRUE)
    rdepends <- sort(unique(unlist(rdepends)))
    pos <- match(rdepends, db[, "Package"], nomatch = 0L)

    db[pos, c("Package", "Version", "Maintainer")]
}

Sys.setenv(http_proxy = "")
a <- reverse_dependencies_with_maintainers("ape", which = c("Depends", "Imports", "Suggests", "LinkingTo"))
a <- a[order(a[,1]),]
ff <- file("depends.txt", open = "w")
cat( paste(sep=",",a[,1],sub("\n","",a[,2]),sub("\n"," ",a[,3]), collapse = "\n"), "\n\n", file=ff)
close(ff)