Wait for user input with readline() while running a whole set of program
0
0
Entering edit mode
shadhiksk • 0
@shadhiksk-13179
Last seen 6.8 years ago

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]

readline scan • 2.0k views
ADD COMMENT

Login before adding your answer.

Traffic: 791 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6