Skip to content
Back to formatted view

Raw Message

Message-ID: <54726DB5.70509@gmail.com>
Date: 2014-11-23T23:28:53Z
From: Serguei Sokol
Subject: [Rcpp-devel] tracking volatile bug
In-Reply-To: <CAP01uR=8m9tH0L3G9ZCz56fCmpjy0qE4D+ZZTgfC5ASGKtAiMw@mail.gmail.com>

Gabor Grothendieck has written at  Sun, 23 Nov 2014 17:57:48 -0500
> 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.
Oops, I must have been under gctorture(FALSE) when it worked.
Under gctorture(TRUE), it does produce an error. wrap(A) that you indicated
is also needed to make the whole call to work.