I have an infinite loop doing a given operation, but at some point (decided by the user), I want the loop to run an alternative operation. Is this possible in R; to stop a loop and modify a variable upon a user hitting a key?
In the code below, for instance, the variable Change is set to TRUE originally, can I after hitting a key, modify that variable to FALSE...and may be back to TRUE in a later time while the loop runs?
Keep=TRUE
while (Keep==TRUE){
Change=TRUE
if (Change==TRUE){
print ("a")
} else {
print ("b")
}
Sys.sleep(1)
}