Problem with the readline() function in r

Viewed 355

I want to take user input into a variable and display it on the screen. However, when I try to take the input using the readline() function it works fine sometimes but not always. Sometimes, I run into the error as below:

enter image description here

So, is there any other function that can take in the user input like the input() function in python.

The code which I have tried is as follows:

my.name <- readline(prompt="Enter name: ")
my.age <- readline(prompt="Enter age: ")
# convert character into integer
my.age <- as.integer(my.age)
print(paste("Hi,", my.name, "next year you will be", my.age+1, "years old."))

Could someone please help me out with this?

1 Answers

Are you using RStudio? If so, the issue is likely due to an incompatibility between your versions of R and RStudio and the solution would be to update your version of RStudio.

Related