On 2013-02-25, at 11:30 PM, Prof Brian Ripley wrote:
> On 25/02/2013 20:00, Davor Cubranic wrote:
>> R.app GUI 1.53 (6335 Leopard build 64-bit) and R 2.15.2 GUI 1.53 Leopard
>> build 64-bit (6335)
>>
>> When I have a long-running call into C or C++, any output I try to print to
>> the console with Rprintf or REprintf appears only after control returns to
>> R, even when the text is terminated with a newline. I managed to force the
>> output to appear immediately by following Rprintf's with R_FlushConsole and
>> R_Process. Is this the recommended way to do it? I haven't had this issue
>> when running R from Terminal or RStudio.
>
> R_FlushConsole is the recommended way: see 'Writing R Extensions'.
R-exts does say this on the topic: "R_FlushConsole is called to flush any
pending output to the system console." But I found that I needed to call both
FlushConsole and ProcessEvents before R.app displayed anything, that's why I
asked. Compare running test1 and test2 below:
library(inline)
library(Rcpp)
test1 <- cxxfunction(
signature(),
body= '
for (int i = 0; i < 20; i++)
{
sleep(1);
if (i%5 == 0) {
Rprintf("%d\\n", i);
R_FlushConsole();
}
}
return wrap(1);
',
plugin="Rcpp")
test2 <- cxxfunction(
signature(),
body= '
for (int i = 0; i < 20; i++)
{
sleep(1);
if (i%5 == 0) {
Rprintf("%d\\n", i);
R_FlushConsole();
R_ProcessEvents();
}
}
return wrap(1);
',
plugin="Rcpp")
test1()
test2()
I didn't find any mention to R.app behaving differently in this respect in the
Mac FAQ either.
Davor
[[alternative HTML version deleted]]
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac