I created a R package which depends on Rcpp. A function in this package supposed to show printing statements at every n iterations. So I expect to see a new line on R console every few seconds.
The odd thing is that when I run my function in R GUI, the cursor becomes a loading wheel and R "almost" freezes. The loading wheel disappear once after the computation is done.
The minimal example of this situation is summarized as follow:
library(inline)
library(Rcpp)
test <- cxxfunction(
signature(),
body= '
RNGScope scope;
for (int i = 0; i < 100; i++)
{
sleep(1); // sleep one second at each iteration. this sleep is
// replaced by something in my code
if (i%20==0) Rprintf("\v%d iterations are done...",i);
}
return wrap(1);
' ,
plugin="Rcpp"
)
test()// freeze for 100 seconds!
I also found that if the code is run on terminal, the new lines appear every 20 seconds as I expected. But I prefer to run it on R GUI.
I would appreciate if someone can tell me why this is happening..
I am using Mac.