I want to ask the user to select any of the options from 1 to 4 and then use the switch statement to transfer the flow accordingly. I have followed this
How to use the switch statement in R functions?
interactive()
num1 <-readline("Select any one of the options")
num <- noquote(num1)
switch(num,
1={
cat('You have selected option 1')
},
2={
print('You have selected option 2')
},
3={
#Option 3
print('You have selected option 3')
},
4={
#Option 4
print('You have selected option 4')
},
{
print('dah make your mind,look at the options again')
}
)
The thing is its not working when I pass a string or number from the readline into switch. I removed the quotes and checked again but still it doesn't work.
I just saved the file and running it like source("file_name.R") Ultimately I want to build an interactive environment, where I collect the variables from the user and perform different tasks based on the options selected by the user.
How can I make it work?