[R] Installed packages: Bioconductor vs CRAN?

Leonard Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Sat Sep 25 02:37:05 CEST 2021


Dear Bert,


Indeed, this seems to work:

installed.packages(fields="Repository")


I still need to figure out what variants to expect.


Sincerely,


Leonard


On 9/25/2021 3:31 AM, Leonard Mada wrote:
> Dear Bert,
>
>
> The DESCRIPTION file contains additional useful information, e.g.:
>
> 1.) Package EBImage:
> biocViews: Visualization
> Packaged: 2021-05-19 23:53:29 UTC; biocbuild
>
>
> 2.) deSolve
> Repository: CRAN
>
>
> I have verified a few of the CRAN packages, and they seem to include 
> the tag:
>
> Repository: CRAN
>
>
> The Bioconductor packages are different (see e.g. EBImage).
>
> I am wondering if there is already a method to extract this info?
>
>
> Sincerely,
>
>
> Leonard
>
>
> On 9/25/2021 3:06 AM, Bert Gunter wrote:
>
>> 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 using 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 using 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.



More information about the R-help mailing list