简体   繁体   中英

Making Rcout output appear on the R console immediately

I have coded an MCMC sampler using Rcpp (specifically, RcppArmadillo ). I would like my sampler to print periodic status messages to the R console, but the messages appear all at once when the sampler terminates. The output statement is :

Rcout << "Progress => " 
      << double(iterations) / double(maxit) * 100 
      << "%" 
      << std::endl;

Can this code be augmented so that its output appears on the R console immediately?

R version: 2.14.1

platform: Darwin 9.8.0

Rcpp version: 0.9.10

This behaviour has been implemented in Rcpp 0.10.0 (to be released soon) following advice from answers to this question .

In the meantime, you can manually call R_FlushConsole

flush() and flush.console() are still broken. R 3.0.2 / OSX

You need a hat trick:

R_FlushConsole();
R_ProcessEvents();
R_CheckUserInterrupt();

Copied from: parallel-computing-in-r-with-c-within-r-functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM