[Rcpp-devel] A simple List example that has me stumped
Dirk Eddelbuettel
edd at debian.org
Mon Sep 17 22:57:27 CEST 2012
On 17 September 2012 at 15:44, Rodney Sparapani wrote:
| On 09/17/2012 03:02 PM, Dirk Eddelbuettel wrote:
| > You are once again tripping over as<>() and wrap(). You_must_ use as<int>
| > as the following working example:
|
| Right. Is there a rule of thumb to determine when we need as<>()?
| I have other examples where it seems to work without it, but I
| can't seem to see a pattern. Or should you just use it all
| of the time whether it is needed or not? Thanks!
Heuristically speaking:
-- always use it for atomistic C/C++ types: int, double, bool, ...
-- rely on SEXP types to corresponding Rcpp types happening automatically
due to implicit use of as<>(), particularly vector / matrix types works:
IntegerVector, NumericMatrix, List, Environment, Function, XPtr, ...
And the same is true for wrap: for sure with int, double, ...; generally not
need for core Rcpp types wrapping a SEXP.
If it fails, the compiler usually tells you. I have not been bitten by
silent failure like the one you reported. But then I also do not try to cram
multiple assignments into a single line...
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list