[R] if/else construct

Schmitt, Corinna Corinna.Schmitt at igb.fraunhofer.de
Fri Apr 13 14:19:13 CEST 2007


Dear R-Experts,

Since Monday I try to write the right if/else construct for the program.
I was not successful yet. Important is the order of the if-cases! The
code is running with the 2 if-cases. An if/else construction would look
better, so can any one help me with the right if/else construction?

Thanks, Corinna
 

Program:
--------

userInput <- function() {
    print("")
    
    ANSWER <- readline("Should the current workspace of R be deleted
(y/n)? ")
    print(ANSWER)
    ANSWER
}

deletingDecision = userInput()
yes <- c("y")
no <- c("n")
noAnswer <- c("Current R workspace was not deleted!")

# first if
if (deletingDecision == no) {                        
    print("Current R workspace was not deleted!")
    }

# second if
if (deletingDecision == yes) {
    rm(list=ls(all=TRUE)) 
    print("Current R workspace was deleted!")
    }



More information about the R-help mailing list