In addition, certain functions, such as library() and require(), expect package names for completions. RStudio automatically infers whether a particular function expects a package name and provides those names as completion...
My question is: how? I'm writing a custom function that takes package names as arguments, yet RStudio's only completing the arguments with object & function names, and I can't tell what it is about the library() and require() code that RStudio is picking up on.
My function is:
unpack <- function(...,
lib = NULL,
repos = getOption("repos")) {
pkgs <- sapply(match.call(expand.dots = TRUE)[-1], as.character)
new.pkgs <-
pkgs[!(
pkgs %in% installed.packages(lib.loc = lib)[, "Package"]
)]
if (length(new.pkgs))
install.packages(new.pkgs,
lib = lib,
repos = repos)
sapply(pkgs, require,
lib.loc = lib,
character.only = TRUE)
}