Dirk Eddelbuettel has written at  Sat, 22 Nov 2014 09:57:36 -0600
On 21 November 2014 at 23:50, Sokol Serguei wrote:
| If I did not use the protection in my Rcpp code it's because
| I did not see it in any example of quick ref guide:
| http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-quickref.pdf
| I didn't see any mention of PROTECT necessity neither in
| http://dirk.eddelbuettel.com/code/rcpp/Rcpp-introduction.pdf
| especially in the part dedicated to the use of wrap().

I am sorry but that is somewhat uncalled for.

We rarely advocate a programming style advocating SEXP manipulation (apart
from rare cases, or in the guts of our code). You programmed the plain C API
for R, apart from using some utility functions from Rcpp to access functions.

For this programming style, you should go to r-devel rather than coming here.
What you do is pretty different from standard Rcpp use, or what we recommend.
If I moved to this style it's because an Rcpp style (at least how I understood it) did not work for me. Obviously, if I can get a "pure" Rcpp code working in this case I would be perfectly happy
with that.


Blaming us
It was not a blaming, just citing my sources.
  for not documenting what we consider inappropriate style is not
only circular but also continues to misunderstand why we do what we do here,
and how we do it.
May be I still misunderstand something but from what I understood
it is perfectly regular to call an R function from rcpp. Well, you say it is not
recommended but if there is no rcpp counterpart neither CCallable interface
what are the alternatives?


| I supposed (very naively, it is clear now) that necessary wrapping and
| protection was automagicaly added behind the stage by Rcpp.

It of course happes automagically if and only if you use Rcpp datatypes.

>From what I understand you did not use those, and hence got no magic.
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.
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to