<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">> In quickref, all examples pass just numbers without any prior conversion</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">> to NumericVector or IntegerVector. Strings are exception to this?</span><br><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Strings are different than numbers in that they don't occupy a fixed</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">amount of space, so some memory management is needed for them.</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">Bill Dunlap<br>TIBCO Software<br>wdunlap <a href="http://tibco.com" target="_blank">tibco.com</a></div></div>
<br><div class="gmail_quote">On Sun, Nov 23, 2014 at 11:07 AM, Sokol Serguei <span dir="ltr"><<a href="mailto:serguei.sokol@gmail.com" target="_blank">serguei.sokol@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Gabor Grothendieck has written at  Sat, 22 Nov 2014 19:17:27 -0500<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sat, Nov 22, 2014 at 1:43 PM, Sokol Serguei<<a href="mailto:serguei.sokol@gmail.com" target="_blank">serguei.sokol@gmail.<u></u>com</a>>  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Let try to stick with regular rcpp code<br>
(file: matrix_norm.cpp):<br>
<br>
//[[Rcpp::depends(<u></u>RcppArmadillo)]]<br>
#include <RcppArmadillo.h><br>
using namespace Rcpp;<br>
using namespace arma;<br>
<br>
// [[Rcpp::export]]<br>
double nmat(mat A) {<br>
    Function Matrix_norm_r_=Environment("<u></u>package:Matrix")["norm"];<br>
    double res=as<double>(Matrix_norm_r_(<u></u>A, "1"));<br>
    return res;<br>
}<br>
<br>
When called in R as:<br>
<br>
library(Rcpp)<br>
library(Matrix)<br>
sourceCpp("matrix_norm.cpp")<br>
gctorture(TRUE)<br>
nmat(as.matrix(pi))<br>
<br>
it gives an error:<br>
Erreur : 'getCharCE' doit être appelé sur un CHARSXP<br>
(my English translation: Error: 'getCharCE' must be called on CHARSXP)<br>
<br>
Something was irregular on my side here?<br>
Serguei.<br>
</blockquote>
Try replacing the line that sets res with:<br>
<br>
    double res=as<double>(Matrix_norm_r_(<u></u>NumericMatrix(wrap(A)),<br>
CharacterVector::create("1")))<u></u>;<br>
<br>
Be sure to try it on a fresh session since errors from prior runs<br>
could have messed up R.<br>
</blockquote>
Yes, this version works too.<br>
The least change that leads to a working code that I have found (thanks to Martin) is<br>
<br>
double res=as<double>(Matrix_norm_r_(<u></u>A, CharacterVector("1")));<br>
<br>
but it is still unclear what is wrong with passing a plain string.<br>
In quickref, all examples pass just numbers without any prior conversion<br>
to NumericVector or IntegerVector. Strings are exception to this?<br>
I have an impression that they are supposed to work too without<br>
any explicit conversion. If you set gctorture(FALSE), it works and<br>
there is no warning or error message that plain strings are not supported<br>
in this place.<br>
So, gctorture() reveals that somewhere there is an un-protected pointer<br>
which is getting corrupted. If it is needed to be said, I don't pretend<br>
that this unprotected pointer is in Rcpp code. May be it is in R, may be<br>
in Matrix, it is still unclear.<br>
<br>
______________________________<u></u>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<u></u>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/rcpp-devel</a></blockquote></div><br></div>