Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function that asks a ~special~ something and returns an answer

I want to do it, but so far all I have is:

print("Will you go out with me?")

I want the code to work so that one can answer yes/no and if answer is yes then a message would return saying like the time, place, etc.

The person I am asking is an R guru so it would mean a lot to them ~~(:

Would love some help. Trying to get that date!

like image 240
Jackie Vazquez Avatar asked Mar 11 '18 00:03

Jackie Vazquez


1 Answers

Put the following into a file and then ask your friend to source the file.

r <- readline("Will you go out with me? (respond 'yes' or 'no'): ")
if(grepl("[Yy]es", r)) {
    cat("Date: 3/10/2018", "Time: 7pm", "Place: McDonalds", sep = "\n")
} else {
    cat("Too bad, I'm a catch.")
}

Now your friend sources the file and BOOM, date!

> source('~/.active-rstudio-document')
Will you go out with me?: yes
Date: 3/10/2018
Time: 7pm
Place: McDonalds

... or BOOM, rejected!

> source('~/.active-rstudio-document')
Will you go out with me?: no
Too bad, I'm a catch.
like image 61
Rich Scriven Avatar answered Sep 30 '22 03:09

Rich Scriven