[R] package dependency tree

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Jan 2 19:07:07 CET 2007


roger koenker wrote:
> Is there a painless way to find the names of all packages on CRAN
> that "Depend" on a specified package?
>   
Depends on how accurately you need them. These *probably* depend on "boot"

> x <- available.packages()

> rownames(x)[grep("boot",x[,"Depends"])]

 [1] "circular"     "cramer"       "DCluster"     "equivalence"  "np"

 [6] "pastecs"      "relaimpo"     "sensitivity"  "simpleboot"   "spdep"

[11] "survrec"      "titan"        "verification" "Zelig"

This allows visual inspection of the Depends fields too:

x[grep("boot",x[,"Depends"]), "Depends", drop=F]    

(There could have been dependencies on, say, simpleboot). For increased precision, 
you'll need to grep more carefully, for "\\<boot\\>". Finally, catching indirect 
dependencies requires iterative application, something like this:

> f <- function(s) rownames(x)[grep(paste("\\<",s,"\\>",sep=""),x[,"Depends"])]
> (y <- f("boot"))
 [1] "circular"     "cramer"       "DCluster"     "equivalence"  "np"
 [6] "pastecs"      "relaimpo"     "sensitivity"  "simpleboot"   "spdep"
[11] "survrec"      "titan"        "verification" "Zelig"
> (y0 <- unlist(lapply(y,f)))
[1] "wle"      "DCluster" "svcR"     "gcmrec"   "VDCutil"
> (y0 <- setdiff(y0,y))
[1] "wle"     "svcR"    "gcmrec"  "VDCutil"
> (y <- union(y, y0))
 [1] "circular"     "cramer"       "DCluster"     "equivalence"  "np"
 [6] "pastecs"      "relaimpo"     "sensitivity"  "simpleboot"   "spdep"
[11] "survrec"      "titan"        "verification" "Zelig"        "wle"
[16] "svcR"         "gcmrec"       "VDCutil"
> (y0 <- unlist(lapply(y0,f)))
character(0)

...and stop at this point since there are no more dependents. Otherwise, repeat.  
 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list