Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Rcout output appear on the R console immediately

Tags:

r

flush

rcpp

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

like image 520
user1815351 Avatar asked Nov 04 '22 11:11

user1815351


1 Answers

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

like image 52
Romain Francois Avatar answered Nov 15 '22 05:11

Romain Francois