cat message is delayed till the end of computation

Viewed 27
library(numbers)
dropletE
function (n) 
{
    stopifnot(is.numeric(n), length(n) == 1, n >= 1)
    if (n > 1000) 
        cat("Warning: Calculating n > 1000 digits will take a long time!\n")
    n <- n + 1
}

Now if I run

dropletE(10000)

the script goes into computation without showing the cat message on the screen (stdout). Only after I select Misc -> Stop All Computations that the message pops out:

Warning: Calculating n > 1000 digits will take a long time!

Q1: Why was printing the message delayed?

Q2: How can I add to this message a 3-way question to the user if s/he wants to continue / change the value or Quit the script?

I am aware of the readline() function but can it be used inside a cat call?

Thanks

0 Answers
Related