[Rcpp-devel] When to use SEXP as return value or argument type?

Dirk Eddelbuettel edd at debian.org
Mon Jun 3 15:09:48 CEST 2013


On 3 June 2013 at 14:35, Asis Hallab wrote:
| Dear Rcpp Experts,
| 
| two simple and short questions:
| 
| Do I always have to use SEXP arguments, if I want the method to be
| callable from R through the .Call( … ) function?

Yes. There is only one interface: .Call(), returning SEXP and taking zero,
one, or more SEXP.

See the "Writing R Extensions" manual.
 
| Does the return type have to be a SEXP, too, or can I use any Rcpp
| class instead?

Rcpp helps by automatically converting from/to SEXP ("implicit as<>() and
wrap()") and also lets you explicitly do so ("explicit as<>() and wrap()").

You can use either form. We sometimes "forget" it has to be SEXP.  In some
case you want to explicitly use SEXP, but those are rare. Please the
documentation, starting with Rcpp-introduction for details, and the various
examples in the list archives, the Rcpp Gallery and elsewhere.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list