[R] Adding comment in C++ code for debugging purpose

Christofer Bogaso bog@@o@chr|@to|er @end|ng |rom gm@||@com
Sat Dec 17 14:38:51 CET 2022


Hi,

Below is the position of Rcout and underlying C++ function

#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){
  Rcpp::Rcout << "Some Value" << std::endl << 1.23 << std::endl;
  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

This still does not print in the console.

Not sure if I am missing something.

Thanks and regards,

On Sat, Dec 17, 2022 at 6:57 PM Rui Barradas <ruipbarradas using sapo.pt> wrote:
>
> Às 11:05 de 17/12/2022, Christofer Bogaso escreveu:
> > Hi Rui,
> >
> > Unfortunately, the code Rcpp::Rcout << "---------->>>>>.My values" <<
> > "\n"; still not printing the value.
> >
> > Regarding your second suggestion, R_Print("My values\n"); - where
> > should I put this statement?
> >
> > On Sat, Dec 17, 2022 at 11:39 AM Rui Barradas <ruipbarradas using sapo.pt> wrote:
> >>
> >> Às 23:32 de 16/12/2022, Christofer Bogaso escreveu:
> >>> Hi,
> >>>
> >>> I am using an R package where there are some C++ code.
> >>>
> >>> To check some intermediate values generated by that C++ code, I added
> >>> a line like
> >>>
> >>> std::cout << "My values";
> >>>
> >>> Now with this modification, I next build a modified package (source) using
> >>>
> >>> R CMD build
> >>>
> >>> Next I install this modified package using install.packages() function
> >>>
> >>> However during the run-time of the C++ code with above modification, I
> >>> dont get any print with "My values"
> >>>
> >>> Can you please help to understand why am not getting that printed?
> >>>
> >>> ______________________________________________
> >>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>
> >> Hello,
> >>
> >> If the package uses Rcpp try instead
> >>
> >>
> >> Rcpp::Rcout << "My values" << "\n";   // or std::endl
> >>
> >>
> >> More generally, there is also
> >>
> >>
> >> R_Print("My values\n");
> >>
> >>
> >>
> >> Hope this helps,
> >>
> >> Rui Barradas
> >>
> >>
> >>
> >>
>
> Hello,
>
> Put R_Print where your cout is and instead of it.
>
> As for Rcpp::Rcout, instead of "\n" try ending the line with std::endl
> to immediately flush the buffer.
>
> Hope this helps,
>
> Rui Barradas
>
>



More information about the R-help mailing list