I cannot find a solution to this particular problem, even though more or less similar questions have been questioned before in:
Running a script from bash is easy enough, however once one needs user interaction I couldn't find a solution. Please consider the example:
userInput<-function(question) {
n = 0
while(n < 1 ){
n <- readline(question)
n <- ifelse(grepl("\\D",n),-1,as.integer(n))
if(is.na(n)){break} # breaks when hit enter
}
return(n)
}
investedLow<- userInput("Invested value in low risk since last time: ")
Now if I save this script as test.R
and run it for R --no-save < teste.R
the entire script is run and the time for user input does not happen.
The script works fine in Rstudio, for example.
- How to wait for user input in a script to be run in the command line?