[Rcpp-devel] Printing intermediate values in C++ code used in Rcpp

Christofer Bogaso bogaso.christofer at gmail.com
Sat Dec 17 12:59:07 CET 2022


Hi,

I am working with a package called

https://cran.r-project.org/src/contrib/GCPM_1.2.2.tar.gz

The source code contains C++ codes which are available in the src folder.

In this folder, the C++ codes are available in cpploss.cpp

In this cpp file, there is a function like below,

#ifdef _OPENMP
#include <omp.h>
#endif
// [[Rcpp::depends(RcppProgress)]]
#include <progress.hpp>
#include "cpploss.h"
#include <Rcpp.h>
#include <Rmath.h>
#include <iostream>

using namespace Rcpp;

// [[Rcpp::export]]
SEXP  GCPM_cpploss(SEXP default_distr_a,SEXP link_function_a, SEXP
S_a,SEXP Sigma_a, SEXP W_a, SEXP PD_a, SEXP PL_a, SEXP calc_rc_a, SEXP
loss_thr_a, SEXP max_entries_a){
  NumericMatrix S(S_a), W(W_a),Sigma(Sigma_a);
  NumericVector PD(PD_a),
PL(PL_a),max_entries(max_entries_a),default_distr(default_distr_a),link_function(link_function_a),calc_rc(calc_rc_a),loss_thr(loss_thr_a);
  List ret;

etc.

However as I run this C++ codes, I want to print some intermediate
values generated by underlying C++ codes for some debugging purposes.
So I added below line (just an example)

Rcpp::Rcout << "Some Value" << std::endl << 1.23 << std::endl;

After adding this line, then after re-building the package and
re-installng it, when I run the R code, I dont get above line printed
in the R console.

Could you please help how can I get designated intermadiate values
printed in my R console when I run the R/C++ code?

Additionally, what is the meaning of the statements like NumericVector
PD(PD_a) etc? I understand that PD_a is the function argument. But
what is the meaning of PD(PD_a)?

Any pointer will be very heklpful.

Thanks for your time.


More information about the Rcpp-devel mailing list