The help file tells you that installed.packages() looks at the DESCRIPTION files of packages. Section 1.1.1 of "Writing R Extensions" tells you what information is in such files.
Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Sep 24, 2021 at 4:56 PM Leonard Mada via R-help <r-help@r-project.org> wrote: > > 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) > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.