As example, I would like to list which these 7 "unavailable" packages are, how should I do?
Thank you in advance!
>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.packagesplus"Status", a factor withlevels 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.
