I am developing an R script in RStudio that requires the user to input two values (a first name and a last name). These inputs will later be used for pattern matching of a text document.
In Python, raw_input would be used to gather these values and I understand that readline(prompt = ) is the associated function in R, but I cannot seem to have my script stop to ask for a value. Instead it appends the next line of code.
My function to prompt the user for names is:
askForName <- function(firstOrLast){
if(firstOrLast == "first"){
x <- readline(prompt = "Enter first name: ")
}
else if(firstOrLast == "last"){
x <- readline(prompt = "Enter last name: ")
}
return(x)
}
When I run:
firstName <- askForName("first")
lastName <- askForName("last")
The console returns:
> firstName <- askForName("first")
Enter first name: lastName <- askForName("last")
How can I get R to wait for a user-inputted value before proceeding through the script?