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

Watal M. Iwasaki heavy.watal at gmail.com
Sat Oct 27 04:53:45 CEST 2018


Yes, escaping from the check seems difficult. I have created a quick PR on
this for further discussion.

Watal

On Sat, Oct 27, 2018 at 2:13 AM Dirk Eddelbuettel <edd at debian.org> wrote:

>
> 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 | edd at debian.org
>


-- 
Watal M. Iwasaki / 岩嵜 航
SOKENDAI, The Graduate University for Advanced Studies,
Hayama, Kanagawa 240-0193, Japan
+81-46-858-1576
https://heavywatal.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20181027/58c2966f/attachment.html>


More information about the Rcpp-devel mailing list