[Rcpp-devel] tracking volatile bug

Gabor Grothendieck ggrothendieck at gmail.com
Sun Nov 23 01:17:27 CET 2014


On Sat, Nov 22, 2014 at 1:43 PM, Sokol Serguei <serguei.sokol at gmail.com> wrote:
> Let try to stick with regular rcpp code
> (file: matrix_norm.cpp):
>
> //[[Rcpp::depends(RcppArmadillo)]]
> #include <RcppArmadillo.h>
> using namespace Rcpp;
> using namespace arma;
>
> // [[Rcpp::export]]
> double nmat(mat A) {
>    Function Matrix_norm_r_=Environment("package:Matrix")["norm"];
>    double res=as<double>(Matrix_norm_r_(A, "1"));
>    return res;
> }
>
> When called in R as:
>
> library(Rcpp)
> library(Matrix)
> sourceCpp("matrix_norm.cpp")
> gctorture(TRUE)
> nmat(as.matrix(pi))
>
> it gives an error:
> Erreur : 'getCharCE' doit être appelé sur un CHARSXP
> (my English translation: Error: 'getCharCE' must be called on CHARSXP)
>
> Something was irregular on my side here?
> Serguei.

Try replacing the line that sets res with:

   double res=as<double>(Matrix_norm_r_(NumericMatrix(wrap(A)),
CharacterVector::create("1")));

Be sure to try it on a fresh session since errors from prior runs
could have messed up R.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com


More information about the Rcpp-devel mailing list