[R] Installed packages: Bioconductor vs CRAN?
Leonard Mada
|eo@m@d@ @end|ng |rom @yon|c@eu
Sat Sep 25 01:55:59 CEST 2021
Dear List Members,
Is there a way to extract if an installed package is from Bioconductor
or if it is a regular Cran package?
The information seems to be *not* available in:
installed.packages()
Sincerely,
Leonard
=======
I started to write some utility functions to analyse installed packages.
The latest version is on Github:
https://github.com/discoleo/R/blob/master/Stat/Tools.CRAN.R
# Basic Info:
info.pkg = function(pkg=NULL) {
if(is.null(pkg)) { pkg = installed.packages(); }
else {
all.pkg = installed.packages();
pkg = all.pkg[all.pkg[,1] %in% pkg, ];
}
p = pkg;
p = as.data.frame(p);
p = p[ , c("Package", "Version", "Built", "Imports")];
return(p);
}
# Imported packages:
imports.pkg = function(pkg=NULL, sort=TRUE) {
p = info.pkg(pkg);
### Imported packages
imp = lapply(p$Imports, function(s) strsplit(s, "[,][ ]*"))
imp = unlist(imp)
imp = imp[ ! is.na(imp)]
# Cleanup:
imp = sub("[ \n\r\t]*+\\([-,. >=0-9\n\t\r]++\\) *+$", "", imp,
perl=TRUE)
imp = sub("^[ \n\r\t]++", "", imp, perl=TRUE);
# Tabulate:
tbl = as.data.frame(table(imp), stringsAsFactors=FALSE);
names(tbl)[1] = "Name";
if(sort) {
id = order(tbl$Freq, decreasing=TRUE);
tbl = tbl[id,];
}
return(tbl);
}
match.imports = function(pkg, x=NULL, quote=FALSE) {
if(is.null(x)) x = info.pkg();
if(quote) {
pkg = paste0("\\Q", pkg, "\\E");
}
# TODO: Use word delimiters?
# "(<?=^|[ \n\r\t],)"
if(length(pkg) == 1) {
isImport = grepl(pkg, x$Imports);
return(x[isImport, ]);
} else {
# TODO: concept?
rez = lapply(pkg, function(p) x[grepl(p, x$Imports), ]);
return(rez);
}
}
Examples:
p = info.pkg();
f = imports.pkg();
### Analyze data
# imported only once: (only in the locally installed packages)
f$Name[f$Freq == 1]
match.imports("hunspell", p)
match.imports("labeling", p)
match.imports("rpart.plot", p)
match.imports(c("pROC", "ROCR"), p)
More information about the R-help
mailing list