CRAN provides manuals for each CRAN package and the manuals contain a list of every function (and dataset) contained in those CRAN packages.
Is there something similar for base R? i.e. where can be found a list of all the functions in base R?
As noted by user alistaire in a comment, help(package = 'base')
will show an index of the functions and data in the base
package.
However, “base R” is generally understood to encompass more than just the base
package, namely the other packages that are also by default loaded by R. This list of packages is accessible via getOption('defaultPackages')
(but note that this list is user modifiable, e.g. in ~/.Rprofile
!).
As of R 4.4.0, this list is (and has been, since at least as far back as R 3.0):
[1] "datasets" "utils" "grDevices" "graphics" "stats" "methods"
If you want to list all exported functions from these packages, use:
core_packages = c(getOption('defaultPackages'), 'base')
core_r_exports = lapply(setNames(core_packages, core_packages), getNamespaceExports)
Strictly speaking this will show you not only functions but also (non-lazy) data: for instance, it will include the vectors LETTERS
and letters
from the ‘base’ package. To exclude those, use a helper function get_functions
instead of getNamespaceExports
:
get_functions = function (pkg) {
as.vector(ls.str(paste0('package:', pkg), all.names = TRUE, mode = 'function'))
}
If, on the other hand, you really want to get all exports from a package, getNamespaceExports
also does not work, since — for reasons that mystify me! — it does not include the pesky lazy data.
So, to also include the exports from the ‘datasets’ package, use the following helper get_exports
instead of getNamespaceExports
:
get_exports = function (pkg) {
ls_all = function (env) ls(env, all.names = TRUE)
if (pkg == 'base') {
# ‘base’ is a special case: calling .getNamespaceInfo() on it fails.
ls_all(.BaseNamespaceEnv)
} else {
ns = getNamespace(pkg)
c(getNamespaceExports(ns), ls_all(.getNamespaceInfo(ns, 'lazydata')))
}
}