[Rcpp-devel] How to handle std::cout/std::cerr in shared libraries

Dirk Eddelbuettel edd at debian.org
Fri Oct 26 17:09:38 CEST 2018


Hi Watal,

On 26 October 2018 at 23:36, Watal M. Iwasaki wrote:
| Is it possible for Rcpp to do some pre-execution hook before user code? For
| example, if Rcpp system can hijack the std::cout buffer by executing
| `std::cout.rdbuf(Rcpp::Rcout.rdbuf())` automatically, then Rcpp users (and
| external libraries) no longer have to care about Rcout, and can just stick
| to std::cout.

Sorry, but we need the opposite (which is what Rcpp::Rcout does): we need to
get what _would otherwise go to std::cout_ and feed it to Rcpp::Rcout which
then hands it to R's buffered i/o.  That is the whole underlying reason --
see the as always very detailed "Writing R Extensions" manual for a bit more.

Automating that (ie replacing std::cout by Rcpp::Rcout) is what is needed.

Dirk


-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list