Question: Wait for user input with readline() while running a whole set of program
0
gravatar for shadhiksk
2.5 years ago by
shadhiksk0
shadhiksk0 wrote:

Hello,

I tried to run a set of functions which need to wait for the user's input but, It is executing taking the next command line as the input. can anyone tell me how can I use the code, so that the console waits for the user to input and assign a value?

I used this command  :

fun1 <- function(x)
  {
  x <- readline(prompt="Please choose the position on x-axis: [T/F]")
     if (x=="T") 
        {
         x<-TRUE
         }
   else if(x=="F"){
           x<-FALSE
   }else{
         print("plz Enter T/F")
          print(fun1())
       }
       return(x)
}
fun2 <- function(x)
{
  x <- readline(prompt="Please choose the position on y-axis: [T/F]")
  if (x=="T") 
  {
    x<-TRUE
  }else if (x=="F"){
    x<-FALSE
  }else{
    print("plz enter T/F")
    print(fun2())
  }
  return(x)
}
sca <- function(x)
{
  x <- readline(prompt="Please enter the scale from 0 and 1: [0,1]")
  x<-as.double(x)
  return(x)
}

the output is when I executed:

> {p1<-print(fun1(p1));
+ p2<-print(fun2(p2));
+ s1<-print(sca(s1))};
Please choose the position on x-axis: [T/F]
[1] "plz Enter T/F"
[1] ""
Please choose the position on y-axis: [T/F]

> {p1<-print(fun1(p1));
+ p2<-print(fun2(p2));
+ s1<-print(sca(s1))}
Please choose the position on x-axis: [T/F]
[1] "plz Enter T/F"
[1] ""
Please choose the position on y-axis: [T/F]f
[1] "plz enter T/F"
[1] "f"
Please enter the scale from 0 and 1: [0,1]

scan readline • 867 views
ADD COMMENTlink written 2.5 years ago by shadhiksk0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 217 users visited in the last hour