Prompt user prior to installing R package

Viewed 242

I have looked at the install.packages help files, Google, and Stack, but I don't see a way to prompt the user prior to installing a package. Is there an install.packages option to require a user prompt asking if the user wants to install the package prior to actually installing the package?

In not possible using install.packages, is there another way to achieve this result?

1 Answers

You can use function menu() inside an if statement to make a simple confirmation mechanism. This will work:

package <- "foo"

if (menu(c("Yes", "No"),
         title= paste("Are you sure you want to install package", package)) == "1") {
    install.packages(package)
} else { print("Cancelling installation")}
Related