Hi Watal,

Thanks for being patient with me :)

On 27 October 2018 at 01:26, Watal M. Iwasaki wrote:
| Sorry for my poor explanation. I have read
| `inst/include/Rcpp/iostream/Rstreambuf.h` and think I understand the role
| of Rcpp::Rcout, but failed to explain my point. By "users [...] can just
| stick to std::cout", I did not mean allowing users to write to stdout via
| std::cout. It is about changing the destination of std::cout from stdout to
| R's i/o. The following code hopefully explains better:
| 
| ```
| // [[Rcpp::export]]
| void example_function() {
|     // Normal state
|     std::cout   << "to stdout; BAD\n";
|     Rcpp::Rcout << "to R's i/o\n";
| 
|     // Ideal state
|     std::streambuf* stdoutbuf = std::cout.rdbuf(Rcpp::Rcout.rdbuf());
|     std::cout   << "to R's i/o via Rcpp::Rcout.buf; GOOD\n"
|     Rcpp::Rcout << "to R's i/o\n";
| 
|     // Restore original state
|     std::cout.rdbuf(stdoutbuf);
|     std::cout   << "to stdout; BAD\n";
|     Rcpp::Rcout << "to R's i/o\n";
| }
| ```
| 
| In other words, we don't have to replace std::cout with Rcpp::Rcout. We
| only have to change its buffer.

I like it!  I think that may fix it.

It may not fix the detection by R CMD check, but if we can show that we do
the right thing maybe this can be adjusted (to also account for Rcpp and
whatever (hidden) macro we may use to provide this.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to