-
-
Notifications
You must be signed in to change notification settings - Fork 218
Description
Recently, I create a demo package vscode-rcpp-demo to demonstrate writing and debugging Rcpp code in VSCode. For debugging, however, it only works well for source files in package when devtools::load_all()
is called which loads the built shared library in src
rather than a tmp directory, and the source file mapping is good for debugging.
For standalone source files, one has to call Rcpp::sourceCpp(file)
to compile and load the shared library which lies in a temp directory and source file is copied and reorganized to include the Rcpp wrapper, which is easy to use but seems more difficult for debugger to do source mapping.
For example, the following source code:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double calc_sum(NumericVector x) {
double sum = 0;
for (int i = 0; i < x.size(); i++) {
sum += x[i];
}
return sum;
}
goes to a temp directory and becomes
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double calc_sum(NumericVector x) {
double sum = 0;
for (int i = 0; i < x.size(); i++) {
sum += x[i];
}
return sum;
}
#include <Rcpp.h>
// calc_sum
double calc_sum(NumericVector x);
RcppExport SEXP sourceCpp_1_calc_sum(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(calc_sum(x));
return rcpp_result_gen;
END_RCPP
}
I'm wondering if it can be also made easier for debugger too?