[R] R behaviour related to user input (readline()) and run selection

Bernzweig, Bruce (Consultant) bbernzwe at bear.com
Mon Jun 25 16:45:51 CEST 2007


When I run the below section of code I get the following error: 

 

       Error in if (co == "A" || co[1] == "O") { : 

              missing value where TRUE/FALSE needed

 

When I run the code in two parts where I first get the user's input

then afterwards run the if/else section, there is no problem.

 

Is there a way to stop the "run selection" process until the user

has input a value?

 

------------------------------------------------------------------------
-----



       calc_option <- function(){

              msg <- cat("Please select an option:\n"," 'O'ne or 'A'll':
")

              co <- readline(msg)

              

              switch(co,

                     O = "O", o = "O",

                     A = "A", a = "A"

              )

       }

       

       co <- calc_option()



       if (co == "A" || co[1] == "O") {

              print(paste("calc_option = ", co))

       } else {

              print("calc_option is not acceptable")

       }





Thanks,



- Bruce

-------------- next part --------------


**********************************************************************
Please be aware that, notwithstanding the fact that the pers...{{dropped}}



More information about the R-help mailing list