[Rcpp-devel] Rostream.h header

Dirk Eddelbuettel edd at debian.org
Sun May 13 17:42:57 CEST 2012


Hi Alexey,

On 13 May 2012 at 16:45, Alexey Stukalov wrote:
| thanks for the quick response, there are some clarifications below.
| 
| I'm trying to use Rcpp::Rostream from my C++ library, not from the inline code,
| so I have to deal with the headers inclusion on my own :)

Oh, now I see more clearly where you come from but I don't yet understand
where you want to go.

| Basically, I want to use Rostream as a log sink for boost::log (this library
| not in the mainline boost yet).
| Because of boost-log API I have to create new Rostream object, using
| Rcpp::Rcout is not an option.
| 
| The minimal code that directs log to R console once the library is loaded looks
| like this:
| 
| #include <Rcpp/iostream/Rostream.h>
| #include <boost/log/trivial.hpp>
| #include <boost/log/sinks.hpp>
| #include <boost/log/core.hpp>
| 
| // Called when the library is loaded and before dlopen() returns
| void __attribute__ ((constructor)) test_load()
| {
|     // initialize boost-log
|     // Construct the R sink
|     typedef boost::log::sinks::synchronous_sink
| <boost::log::sinks::text_ostream_backend> text_sink;
|     boost::shared_ptr< text_sink > pRSink = boost::make_shared< text_sink >
| ();
| 
|     // Add a stream to write log to
|     pRSink->locked_backend()->add_stream( boost::make_shared<Rcpp::Rostream>
| () );
| 
|     // Register the sink in the logging core
|     boost::log::core::get()->add_sink(pRSink);
| 
|     BOOST_LOG_TRIVIAL(info) << "R test library loaded";
| }
| 
| // Called when the library is unloaded and before dlclose() returns
| void __attribute__ ((destructor)) test_unload()
| {
| }
| 
| To make this code work I had to add #include "Rstreambuf.h" into <Rostream.h>
| for the reasons described above.
| I hope now it's more clear.

And this is code that you call from R?

This is basically outside of our current scope.  Rcpp doesn't use Boost
itself, so we can't promise that it works with boost::log etc -- this is
essentially something you need to work out.

That said, it could be made to work.  If you can suggest patches for our
header files that will help you without affecting prior behaviour, we could
possibly include.  Rcpp::Rostream is a good example as Jelmer added this
without affecting anything else.

Does that make sense?

Dirk

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


More information about the Rcpp-devel mailing list