[Rcpp-devel] tracking volatile bug

Gabor Grothendieck ggrothendieck at gmail.com
Sun Nov 23 23:57:48 CET 2014


On Sun, Nov 23, 2014 at 2:07 PM, Sokol Serguei <serguei.sokol at gmail.com> wrote:
> Gabor Grothendieck has written at  Sat, 22 Nov 2014 19:17:27 -0500
>
>> 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.
>
> Yes, this version works too.
> The least change that leads to a working code that I have found (thanks to
> Martin) is
>
> double res=as<double>(Matrix_norm_r_(A, CharacterVector("1")));
>
> but it is still unclear what is wrong with passing a plain string.
> In quickref, all examples pass just numbers without any prior conversion
> to NumericVector or IntegerVector. Strings are exception to this?

Not on my system.  That fails for me with the same error you got.

I am using

> packageVersion("Rcpp")
[1] ‘0.11.3’
> gctorture(FALSE)
> packageVersion("RcppArmadillo")
[1] ‘0.4.500.0’
> R.version.string
[1] "R version 3.1.2 RC (2014-10-25 r66870)"

Under Windows 8.1 with Rtools version 3.1.0..1942 (which uses g++ 4.6.3)

-- 
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