I have the following function which requires a sequence of user inputs:
fun <- function(){
cat("Hello! let's input some data")
x <- readline("Input foo: ")
y <- readline("Input bar: ")
z <- readline("Input baz: ")
a <- readline("Input foobarbaz: ")
}
fun()
However, when I call fun()
after the function is defined, it often skips
directly to the second input - Input bar:
why is readlines()
asynchronous in a function? Does it have to do with assigning the input to a variable?
In the console:
> fun()
Hello! let's input some dataInput foo:
Input bar:
I would like the inputs to appear in the same order as they are written in the function.
Why does this happen and what is the workaround?