[R-pkg-devel] How ton print in the console from Rcpp

Iñaki Ucar |uc@r @end|ng |rom |edor@project@org
Thu Oct 20 13:37:04 CEST 2022


Hi,

On Thu, 20 Oct 2022 at 12:42, Elysée Aristide <ariel92and using gmail.com> wrote:
>
> Greetings,
>
> In my CDatanet package, I want to print texts and values during a numerical
> optimization process. I saw in many posts that CRAN is not happy with
> sd::cout and sd::endl. What I understood is that it is better to use Rcpp
> functions. So I used:
>
> Rcpp::Rcout << "beta: \n";
> Rcpp::print(betacpp);
> Rcpp::Rcout << "log-likelihood: " << llh << "\n";
>
> Everything is fine with the check --as-cran with Linux and Windows.
> However, there is a warning with Mac (
> https://www.r-project.org/nosvn/R.check/r-release-macos-arm64/CDatanet-00check.html
> )
> checking compiled code ... WARNING
> File ‘CDatanet/libs/CDatanet.so’:
>   Found ‘___assert_rtn’, possibly from ‘assert’ (C)
>     Objects: ‘CDincomInfo.o’, ‘CDincomInfo.rho.o’, ‘Homophily.o’,
>       ‘RcppExports.o’, ‘SARTIncomplet.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.
>
> I think this is because I am printing from C++ functions. Am I wrong? If
> not, what is the best way to print in the console from C++ functions?

No, this is not related to the use of printing functions. It seems to
be related to RcppEigen according to this:
https://stackoverflow.com/questions/70415854/helps-on-the-package-development

On Linux, I don't see ___assert_rtn being included in the final shared
library (this seems to happen only for macOS for some reason). What I
did find in the shared library is this:

(internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array))
& (15)) == 0 && "this assertion is explained here: "
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html"
" **** READ THIS WEB PAGE !!! ****"

Not sure if this is related to the issue you see, but it seems likely.

-- 
Iñaki Úcar



More information about the R-package-devel mailing list