9

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!

zx8754
  • 52,746
  • 12
  • 114
  • 209

1 Answers1

6

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.
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245