Search code examples
rpromptreadlineuser-interaction

R user interaction when choosing model


I have generated nine models using lm() in R, which I've named m1-m9. I'd like to create a prompt whereby the user answers the question:

"Which model would you like to use for further analysis? (m1-m9)"

with the name of the model (m1-m9), simply stated as e.g. "m1". I then want to use the answer given to copy the original model (m1-m9), but rename the copy as "calmod" which will be used for further analysis. I've read several threads dealing with prompts but I'm simply too much of a beginner to get my head around it. Is there any simple way to do this?

Cheers


Solution

  • Interesting question! We can use

    input <- readline("Which model would you like to use for further analysis? (m1-m9): ")
    calmod <- get(input)