Different ways to make your R session interactive for asking question and receive the answer as an input.

readline

You can find some example in StackOverflow or Geeksforgeeks. Basically is just like this:

cp <- as.integer(readline(prompt = "Vil du kopiere filen? Svar 0=Nei 1=Ja "))

utils::menu

An example is from StackOverflow or from the documentation. You can use GUI is Windows or MacOS. This is how I use the functions:

    msgs <- sprintf("\nWoops!! Table `%s allready exists. What will you do?", table)
    answer <- utils::menu(c("Overwrite", "Append", "Cancel"), title = msgs)

utils::askYesNo

This gives the output as TRUE, FALSE or NA. You can read the documentation for some examples.

out <- utils::askYesNo("Do you can to proceed?")
prompt 
comments powered by Disqus