Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to list "unavailable packages" in packageStatus()?

As example, I would like to list which these 7 "unavailable" packages are, how should I do?

Thank you in advance!

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As the packageStatus() docs note, it returns a list with two components. The one we’re interested in is inst:

a data frame with columns as the matrix returned by installed.packages plus "Status", a factor with levels c("ok", "upgrade", "unavailable").

Here’s a function to extract it:

get_packages_with_status <- function(status = "unavailable", names_only = TRUE, ...) {
    pkgs <- packageStatus(...)
    tbl <- pkgs$inst[pkgs$inst$Status == status, ]
    if (names_only) {
        return(unname(tbl$Package))
    }
    tbl
}

The output should be something like:

get_packages_with_status()
#  [1] "assertive"            "assertive.code"       "assertive.data"       "assertive.data.uk"    "assertive.data.us"    "assertive.datetimes" 
#  [7] "assertive.properties" "assertive.reflection" "assertive.strings"    "assertive.types"      "BiocGenerics"         "BiocVersion"         
# [13] "cqcapi"               "cqcrequests"          "echarts4r.maps"       "estimability"         "geojsonlint"          "getnews"             
# [19] "graph"                "hexjsonwidget"        "maptools"             "optiRum"              "pwrcalc"              "rgdal"               

Of if you want the full data frame.

get_packages_with_status(names_only = FALSE)
#                                   Package                                     LibPath    Version Priority                                         Depends
# assertive                       assertive /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.3-6     <NA>                                    R (>= 3.0.0)
# assertive.code             assertive.code /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-3     <NA>                                    R (>= 3.0.0)
# assertive.data             assertive.data /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-3     <NA>                                    R (>= 3.0.0)
# assertive.data.uk       assertive.data.uk /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-2     <NA>                                    R (>= 3.0.0)
# assertive.data.us       assertive.data.us /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-2     <NA>                                    R (>= 3.0.0)
# assertive.datetimes   assertive.datetimes /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-3     <NA>                                    R (>= 3.0.0)
# assertive.properties assertive.properties /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-5     <NA>                                    R (>= 3.0.0)
# assertive.reflection assertive.reflection /home/sam/R/x86_64-pc-linux-gnu-library/4.2      0.0-5     <NA>                                    R (>= 3.0.0)
# <etc>

Note also the definition of available depends on what you supply as the argument to repositories:

a character vector of URLs describing the location of R package repositories on the Internet or on the local machine. If specified as NULL, derive appropriate URLs from option "repos".

This is why, as noted by MrFlick’s comment, in my list I can see packages listed as unavailable even though I know they’re installed, because they were installed from GitHub or locally.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading