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

From: Bernzweig, Bruce (Consultant) <bbernzwe_at_bear.com>
Date: Mon, 25 Jun 2007 10:45:51 -0400


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,


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



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 25 Jun 2007 - 15:18:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 25 Jun 2007 - 17:32:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.