How can I get R to list its base install packages. Dirk gives a list HERE but how can I get R to tell me this information, that is the packages in src/library/?
getOption("defaultPackages") is close but only lists some of these packages.
How can I get R to list its base install packages. Dirk gives a list HERE but how can I get R to tell me this information, that is the packages in src/library/?
getOption("defaultPackages") is close but only lists some of these packages.
rownames(installed.packages(priority="base"))
[1] "base" "compiler" "datasets" "graphics" "grDevices" "grid"
[7] "methods" "parallel" "splines" "stats" "stats4" "tcltk"
[13] "tools" "utils"
TL;DR.
rownames(installed.packages(priority = "base")) all base packages for your R.Version().c(getOption("defaultPackages"), "base") is what R loads on startupinstalled.packages will return your currently installed packages.
Where base packages are always the same per certain R version (R.Version()). It is possible that this list will change in the future with a newer R version. E.g. As i remember parallel was added later than others R `parallel` package does not exist on CRAN?.
getOption("defaultPackages") is what R loads on startup although the base package is not counted.
I find out that sessionInfo()$basePkgs solution is more robust for startup packages as it contains a base package too. However sessionInfo()$basePkgs is relatively highly inefficient because it is a simple loop across all DESCRIPTION files.
microbenchmark::microbenchmark(sessionInfo()$basePkgs,
getOption("defaultPackages"))
Unit: nanoseconds
expr min lq mean median uq max neval
sessionInfo()$basePkgs 6172017 6242209 6673759.42 6294546 6848292 16656578 100
getOption("defaultPackages") 205 246 526.85 451 656 1722 100
There might be a simpler method, but I think that this should do the trick:
installed.packages()[grep('^base$', installed.packages()[, 'Priority']), ]