[Rcpp-devel] S3 methods with cppFunction/sourceCpp

JJ Allaire jj.allaire at gmail.com
Thu Dec 27 23:06:41 CET 2012


Hi Chistian,

With sourceCpp, you can actually specify an exported function name
explicitly in the export declaration. For example:

// [[Rcpp::export("fun.class")]]

So this will work for sourceCpp but alas isn't currently possible for
cppFunction. One way around this for cppFunction would be to pass env
= NULL to cppFunction which will result in the function being returned
rather than added to the calling environment. You could then wrap the
returned function in an appropriately named S3 function.

J.J.

On Thu, Dec 27, 2012 at 4:54 PM, Christian Gunning <xian at unm.edu> wrote:
> I just realized that cppFunction can't natively build S3 functions, since
>  fun.class isn't valid C++ function name.  I'm wondering if adding and
>  S3class argument (default value = FALSE, otherwise class name as
>  character) to cppFunction makes sense -- all that's needed is
>  appending the class name to the function name, correct?  The downside,
> as I see it, is that it's not so simple for sourceCpp/attributes (at
> least I don't understand them).
>
> Obviously, this is a minor issue. Is anyone else likely to hit this?
>
> best,
> Christian
>
>
> --
> A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!


More information about the Rcpp-devel mailing list