8

I would like to read an input given by User in R programming through message window.

For example, It should give a message "enter the number" in a pop up box along with option of entering a number in the message box itself. Then I would like to store that number in a variable.

Thanks for your help in advance..!

avinash talari
  • 93
  • 1
  • 2
  • 4
  • There are lots of suggestions [here](https://stackoverflow.com/questions/11007178/creating-a-prompt-answer-system-to-input-data-into-r) – Michael Bird Sep 08 '17 at 12:37

1 Answers1

28

The svDialogs provides such solution.

library(svDialogs)
user.input <- dlgInput("Enter a number", Sys.info()["user"])$res

which gives a pop-up as

snap1

Also, user input is stores

> user.input
[1] "68"
parth
  • 1,571
  • 15
  • 24
  • 1
    This does not work in a Jupyter Notebook. It works fine from a RTerm command line. Anyone know why this is the case? – Rich Lysakowski PhD Feb 20 '20 at 20:34
  • Thanks a lot. If you write a number, do not forget to convert using as.numeric(user.input) in order to be able to be used – Laurent Feb 05 '21 at 04:20
  • 1
    Thank you, it is very helpful. The $res confused me at the beginning, later I realised that dlgInput() actually create a list, and res is an element within it. – Grasshopper_NZ Jan 15 '23 at 23:38