Watal M. Iwasaki
2018-10-26 07:31:13 UTC
Hi all,
I have been working on an R interface package to a shared library written
in C++. It works almost perfectly, but the output to std::cout is not shown
on R console (on Linux). Of course Rcpp::Rcout should be used instead of
std::cout. But in this case I want to let the shared library be pure C++.
So I tried switching the stream buffers in the Rcpp side:
```
Rcpp::CharacterVector run(const std::vector<std::string>& args) {
std::streambuf* obuf = std::cout.rdbuf(Rcpp::Rcout.rdbuf());
mylib::Simulation simulation(args);
simulation.run(); // std::cout is used in here
std::cout.rdbuf(obuf);
return "something";
}
```
It (seemingly) works! But now `devtools::check()` produces 1 note:
```
⯠checking compiled code ... NOTE
File âmylib/libs/mylib.soâ:
Found â__ZNSt3__14coutEâ, possibly from âstd::coutâ (C++)
Object: ârun.oâ
Compiled code should not call entry points which might terminate R nor
write to stdout/stderr instead of to the console, nor use Fortran I/O
nor system RNGs.
```
Can I suppress this note? or should I just ignore it? any other good
solution?
Thanks,
Watal M. Iwasaki
I have been working on an R interface package to a shared library written
in C++. It works almost perfectly, but the output to std::cout is not shown
on R console (on Linux). Of course Rcpp::Rcout should be used instead of
std::cout. But in this case I want to let the shared library be pure C++.
So I tried switching the stream buffers in the Rcpp side:
```
Rcpp::CharacterVector run(const std::vector<std::string>& args) {
std::streambuf* obuf = std::cout.rdbuf(Rcpp::Rcout.rdbuf());
mylib::Simulation simulation(args);
simulation.run(); // std::cout is used in here
std::cout.rdbuf(obuf);
return "something";
}
```
It (seemingly) works! But now `devtools::check()` produces 1 note:
```
⯠checking compiled code ... NOTE
File âmylib/libs/mylib.soâ:
Found â__ZNSt3__14coutEâ, possibly from âstd::coutâ (C++)
Object: ârun.oâ
Compiled code should not call entry points which might terminate R nor
write to stdout/stderr instead of to the console, nor use Fortran I/O
nor system RNGs.
```
Can I suppress this note? or should I just ignore it? any other good
solution?
Thanks,
Watal M. Iwasaki