<br><br><div class="gmail_quote">On Sun, May 13, 2012 at 5:42 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hi Alexey,<br>
<div class="im"><br>
On 13 May 2012 at 16:45, Alexey Stukalov wrote:<br>
| thanks for the quick response, there are some clarifications below.<br>
|<br>
</div><div class="im">| I'm trying to use Rcpp::Rostream from my C++ library, not from the inline code,<br>
| so I have to deal with the headers inclusion on my own :)<br>
<br>
</div>Oh, now I see more clearly where you come from but I don't yet understand<br>
where you want to go.<br>
<div><div class="h5"><br>
| Basically, I want to use Rostream as a log sink for boost::log (this library<br>
| not in the mainline boost yet).<br>
| Because of boost-log API I have to create new Rostream object, using<br>
| Rcpp::Rcout is not an option.<br>
|<br>
| The minimal code that directs log to R console once the library is loaded looks<br>
| like this:<br>
|<br>
| #include <Rcpp/iostream/Rostream.h><br>
| #include <boost/log/trivial.hpp><br>
| #include <boost/log/sinks.hpp><br>
| #include <boost/log/core.hpp><br>
|<br>
| // Called when the library is loaded and before dlopen() returns<br>
| void __attribute__ ((constructor)) test_load()<br>
| {<br>
|     // initialize boost-log<br>
|     // Construct the R sink<br>
|     typedef boost::log::sinks::synchronous_sink<br>
| <boost::log::sinks::text_ostream_backend> text_sink;<br>
|     boost::shared_ptr< text_sink > pRSink = boost::make_shared< text_sink ><br>
| ();<br>
|<br>
|     // Add a stream to write log to<br>
|     pRSink->locked_backend()->add_stream( boost::make_shared<Rcpp::Rostream><br>
| () );<br>
|<br>
|     // Register the sink in the logging core<br>
|     boost::log::core::get()->add_sink(pRSink);<br>
|<br>
|     BOOST_LOG_TRIVIAL(info) << "R test library loaded";<br>
| }<br>
|<br>
| // Called when the library is unloaded and before dlclose() returns<br>
| void __attribute__ ((destructor)) test_unload()<br>
| {<br>
| }<br>
|<br>
| To make this code work I had to add #include "Rstreambuf.h" into <Rostream.h><br>
| for the reasons described above.<br>
| I hope now it's more clear.<br>
<br>
</div></div>And this is code that you call from R?<br>
<br>
This is basically outside of our current scope.  Rcpp doesn't use Boost<br>
itself, so we can't promise that it works with boost::log etc -- this is<br>
essentially something you need to work out.<br>
<br>
That said, it could be made to work.  If you can suggest patches for our<br>
header files that will help you without affecting prior behaviour, we could<br>
possibly include.  Rcpp::Rostream is a good example as Jelmer added this<br>
without affecting anything else.<br>
<br>
Does that make sense?<br></blockquote><div><br></div><div>Actually, the example above works just fine, since Rostream conforms to ostream concept.</div><div>I just had to make the following change to Rostream.h to make it compile:</div>
<div><br></div><div><div>--- /usr/lib64/R/library/Rcpp/include/Rcpp/iostream/Rostream.h  2012-05-13 17:50:58.090987364 +0200</div><div>+++ /fast/opt/lib64/R/library/Rcpp/include/Rcpp/iostream/Rostream.h     2012-05-10 13:52:45.542940000 +0200</div>
<div>@@ -24,6 +24,8 @@</div><div> </div><div> #include <iomanip>                             // USES setw</div><div> </div><div>+#include "Rstreambuf.h"</div><div>+</div><div> // modified from </div><div> // <a href="http://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file">http://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file</a></div>
<div><br></div></div><div>It would be nice if you can apply this tiny patch.</div><div><br></div><div>Thanks,</div><div>   Alexey</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></span></blockquote></div><br>