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

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 25 Jun 2007 12:35:31 -0400

First of all you don't appear to be returning anything from your function, so 'co' is NULL and your 'if' statement fails. You were also probably cut/paste the code in, and the readline was reading from the statements you pasted. Try sourcing in the code.

On 6/25/07, Bernzweig, Bruce (Consultant) <bbernzwe_at_bear.com> wrote:
>
> 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
>
>
>
>
> **********************************************************************
> 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.
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
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 - 16:39:51 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.