[Rd] C code hanging and printing everything at the end

Simon Urbanek simon.urbanek at r-project.org
Tue Jan 4 18:09:06 CET 2011


On Jan 4, 2011, at 11:41 AM, Robert Lowe wrote:

> Hi,
> 
> I am currently writing an extension for R and have the need to include some C code. If I call the code with a large amount of data then it can take several minutes to complete.
> 
> The C code prints out after a certain iteration hence letting the user know it hasn't crashed.
> 
> When running in R this generally does not happen and all is printed out at the end once the program has completed successfully.
> 
> I am using Rprintf() to print out the required output.
> 
> e.g. Something simple which illustrates my point
> 
> for(int i=0; i<10000; i++){
> 	#Calculations
> 	if (i%1000==0){
> 		Rprintf("Step %d\n",i)
> 	}
> }
> 
> All I get during the program is the OS X spinning wheel in R. Is there any way to print out as the program is running?
> 

You want to add R_CheckUserInterrupt(); so that the system has a chance to run the event loop and thus display the result. But the implication is that you may be interrupted so make sure R controls any memory allocations you have made.

Cheers,
Simon



More information about the R-devel mailing list