<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Dear Dirk,<div><br></div><div>Thank you for the prompt response. Good to know there is no easy way. I have made up my mind to change the library code as you suggested. But I don't like preprocessor macro; therefore, the problem here was solved by moving/hiding `std::cout.rdbuf()` part into the library as a function that takes a streambuf pointer, and just calling it from Rcpp side. Now, output is properly sent to R console, R CMD check complains nothing, and the library still remains free from R/Rcpp code. Thanks again.</div><div><br></div><div>Best,</div><div>Watal</div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Oct 26, 2018 at 9:29 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 26 October 2018 at 16:31, Watal M. Iwasaki wrote:<br>
| I have been working on an R interface package to a shared library written<br>
| in C++. It works almost perfectly, but the output to std::cout is not shown<br>
| on R console (on Linux). Of course Rcpp::Rcout should be used instead of<br>
| std::cout. But in this case I want to let the shared library be pure C++.<br>
| So I tried switching the stream buffers in the Rcpp side:<br>
| ```<br>
| Rcpp::CharacterVector run(const std::vector<std::string>& args) {<br>
|     std::streambuf* obuf = std::cout.rdbuf(Rcpp::Rcout.rdbuf());<br>
|     mylib::Simulation simulation(args);<br>
|     simulation.run(); // std::cout is used in here<br>
|     std::cout.rdbuf(obuf);<br>
|     return "something";<br>
| }<br>
| ```<br>
| <br>
| It (seemingly) works! But now `devtools::check()` produces 1 note:<br>
| ```<br>
| ❯ checking compiled code ... NOTE<br>
|   File ‘mylib/libs/mylib.so’:<br>
|     Found ‘__ZNSt3__14coutE’, possibly from ‘std::cout’ (C++)<br>
|       Object: ‘run.o’<br>
| <br>
|   Compiled code should not call entry points which might terminate R nor<br>
|   write to stdout/stderr instead of to the console, nor use Fortran I/O<br>
|   nor system RNGs.<br>
| ```<br>
| <br>
| Can I suppress this note? or should I just ignore it? any other good<br>
| solution?<br>
<br>
You need to change it. There is no automatic fix.<br>
<br>
[ Longer answer: See eg what we do in RcppArmadillo where we #define a device<br>
which for builds that we do from R fills in Rcpp::Rcout and otherwise<br>
defaults to std::cout.  But the essence is the same: _You_ need to change<br>
that library code to conform.  Or keep the library outside the R package but<br>
then you have an external dependency. ]<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Watal M. Iwasaki / 岩嵜 航<br>SOKENDAI, The Graduate University for Advanced Studies,<br>Hayama, Kanagawa 240-0193, Japan<br>+81-46-858-1576<br><a href="https://heavywatal.github.io/" target="_blank">https://heavywatal.github.io/</a></div></div>