[Rcpp-devel] Convention on where to put RCPP_MODULE declarations?

Douglas Bates bates at stat.wisc.edu
Tue Nov 16 14:53:00 CET 2010


Thanks to you and to Andrew for the responses.  I will put the module
declaration in a separate .cpp file.

On Tue, Nov 16, 2010 at 2:50 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
> Le 16/11/10 03:50, Douglas Bates a écrit :
>>
>> Is there any guidance on where to put RCPP_MODULE declarations in
>> package sources?  I'm working on the assumption of one module per
>> package but the module itself can contain multiple class or function
>> declarations.  Is one module per package reasonable or would there be
>> a reason for multiple modules in a package?
>>
>> I typically keep class declarations and definitions in separate files,
>> usually one class per pair of files.  To me it seems that the module
>> declaration belongs in a header file but I haven't looked closely at
>> what it expands to.  Should it be in a header file or a .cpp source
>> code file?
>
> I know from previous conversations that this might not be of interest, but
> here's the definition of RCPP_MODULE anyway:
>
> #define RCPP_MODULE(name)                                            \
> void _rcpp_module_##name##_init() ;                                  \
> static Rcpp::Module _rcpp_module_##name( # name ) ;                  \
> extern "C" SEXP _rcpp_module_boot_##name(){                          \
>  ::setCurrentScope( & _rcpp_module_##name ) ;                       \
>  _rcpp_module_##name##_init( ) ;                                    \
>  Rcpp::XPtr<Rcpp::Module> mod_xp( & _rcpp_module_##name , false ) ; \
>  ::setCurrentScope( 0 ) ;                                           \
>  return mod_xp ;                                                    \
> }                                                                    \
> void _rcpp_module_##name##_init()
>
>
>
> I'm specially concerned about the "static" in the third line. I think for
> that reason, it has to be in a .cpp file.
>
> I would declare classes and functions in headers, define them in a .cpp file
> and module them in a separate file.
>
> There is no design restrictions about the number of modules per package, so
> if it does not work it is a bug. I simply have not tried it as I'm happy
> with a single one.
>
> Romain
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
> http://romainfrancois.blog.free.fr
> |- http://bit.ly/9VOd3l : ZAT! 2010
> |- http://bit.ly/c6DzuX : Impressionnism with R
> `- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>


More information about the Rcpp-devel mailing list