Make R wait for user

Asked

Viewed 87 times

0

I have a complete program in R, where you first ask the user for a number, using the menu function:

menu(c('1','2','3'),title='Escolha um numero')

Then, a few lines of code below, this chosen number is necessary for some functions. The program is required to be as independent as possible, i.e., user "Run all", enter the number and then the program runs alone and gives the final result. The problem is that when performing "Run all", the program does not wait for the user to enter the number and executes an infinite cycle or the program gives error. Is there a function that can make R wait for the user to enter the number and only then continue the program using "Run all"?

  • For me your code alone should work normally, but it’s not clear what you want beyond that. It might be interesting to include more lines of code so someone can help you.

  • The user has to choose a number and only then can follow the program, my goal is that when the user does "run all" R wait for the user to enter a number and then continue. I’ve tried using the source function to fetch another file as well: if Interactive()==TRUE continue the program if Interactive()==FALSE re-ask But it still fails because R does not expect the answer

  • 1

    Already used Shiny to make a user interface?

  • No, I will look at how to use it. But that means using Rstudio and I have to work on R but thank you for the answer.

  • 1

    Have you tried using readline(prompt="Enter a number")

  • Yes already, but that’s not the problem. The question was poorly explained, I already edited I think is clearer now

  • 1
Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.