[Rcpp-devel] S3 methods with cppFunction/sourceCpp
Christian Gunning
xian at unm.edu
Thu Dec 27 23:25:37 CET 2012
On Thu, Dec 27, 2012 at 4:06 PM, JJ Allaire <jj.allaire at gmail.com> wrote:
> Hi Chistian,
>
> With sourceCpp, you can actually specify an exported function name
> explicitly in the export declaration. For example:
>
> // [[Rcpp::export("fun.class")]]
Great, thanks. I hadn't tried that. I did search the Rcpp-attributes
vignette for S3 and class. Maybe add a short note in section 2.5? As
I said, I don't see this as a big deal :)
> 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.
Cool, that makes sense. Thanks for the quick reply!
-Christian
> 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!
>
>
--
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