Discussion:
[Rcpp-devel] Different Rcout object for each translation unit
Iñaki Ucar
2018-12-03 18:33:58 UTC
Permalink
Hi,

Rcout is defined in iostream/Rstreambuf.h as a static object. This
means that different translation units see a different Rcout, while
they see the same std::cout (I have a minimal package showing this if
needed). As a result, for example, one object allocated in a certain
.cpp cannot redirect the output of other object allocated in another
.cpp. Is there any solution to this (apart from putting everything in
a huge .cpp)?

Regards,
--
Iñaki Úcar
Kevin Ushey
2018-12-03 19:32:31 UTC
Permalink
I think this might be worth fixing on the Rcpp side -- there should
really only be one instance of the Rcout object. Would you mind filing
an issue at https://github.com/RcppCore/Rcpp/issues, so we don't lose
track of this?

You could of course just create your own Rcout / Rcerr objects as well
(the Rstreambuf class is public and part of the Rcpp namespace).

Kevin
Post by Iñaki Ucar
Hi,
Rcout is defined in iostream/Rstreambuf.h as a static object. This
means that different translation units see a different Rcout, while
they see the same std::cout (I have a minimal package showing this if
needed). As a result, for example, one object allocated in a certain
.cpp cannot redirect the output of other object allocated in another
.cpp. Is there any solution to this (apart from putting everything in
a huge .cpp)?
Regards,
--
Iñaki Úcar
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Iñaki Ucar
2018-12-03 19:41:14 UTC
Permalink
Post by Kevin Ushey
I think this might be worth fixing on the Rcpp side -- there should
really only be one instance of the Rcout object. Would you mind filing
an issue at https://github.com/RcppCore/Rcpp/issues, so we don't lose
track of this?
Sure, no problem.
Post by Kevin Ushey
You could of course just create your own Rcout / Rcerr objects as well
(the Rstreambuf class is public and part of the Rcpp namespace).
Yeap, but that's suboptimal. I agree that this might be worth fixing
on the Rcpp side. I asked first here because I'm not sure if that's
possible, because packages cannot (in general) link to other packages.

Iñaki

Loading...