Skip to content

[Rcpp-devel] Working with modules

2 messages · Wagner Bonat, Dirk Eddelbuettel

#
Dear all,

I am reading the Rcpp book Chapter 7 - Modules

The first example provide a C++ function

## C++ function
double norm( double x, double y){
        return sqrt(x*x + y*y);
}

## Simple wrapper function
using namespace Rcpp;
RcppExport SEXP norm_wrapper(SEXP x_, SEXP_y){
    double x = as<double>(x_), y = as<double>(y_);
    double res = norm(x,y);
    return wrap(res);
}

So, I have these two functions. But, I am lost, what should I do now?

The goal is make the function norm available in R.

Probably, this is a very basic question, so if anyone know some material on
the internet that explain the missing parts here, please let me know.

Thank you.
#
On 4 June 2015 at 16:35, Wagner Bonat wrote:
| Dear all,
| 
| I am reading the Rcpp book Chapter 7 - Modules
| 
| The first example provide a C++ function
| 
| ## C++ function
| double norm( double x, double y){
| ??????? return sqrt(x*x + y*y);
| }
| 
| ## Simple wrapper function
| using namespace Rcpp;
| RcppExport SEXP norm_wrapper(SEXP x_, SEXP_y){
| ??? double x = as<double>(x_), y = as<double>(y_);
| ??? double res = norm(x,y);
| ??? return wrap(res);
| }
| 
| So, I have these two functions. But, I am lost, what should I do now?

Maybe consider the rest of the chapter?

Modules work best, I find, when you use a complete package.

Our unit tests contain one (see unitTests/testRcppModule) and you can also
set an example up via

R> Rcpp.package.skeleton(name="modTest", path="/tmp", module=TRUE)
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in '/tmp/modTest/Read-and-delete-me'.

Adding Rcpp settings
 >> added Imports: Rcpp
 >> added LinkingTo: Rcpp
 >> added useDynLib directive to NAMESPACE
 >> added import(methods, Rcpp) directive to NAMESPACE
 >> added example src file using Rcpp attributes
 >> compiled Rcpp attributes
 >> added Rd file for rcpp_hello_world
 >> copied the example module file 
R>

Packages created with variants of package.skeleton have their own issues (of
not passing R CMD check) but that is an R issue, not an Rcpp issue...

Dirk


| The goal is make the function norm available in R.
| 
| Probably, this is a very basic question, so if anyone know some material on the
| internet that explain the missing parts here, please let me know.
| 
| Thank you.
| 
| 
| 
| 
| --
| Wagner Hugo Bonat
| ----------------------------------------------------------------------------------------------
| Department of Mathematics and Computer Science (IMADA)
| University of Southern Denmark (SDU) and
| Laborat?rio de Estat?stica e Geoinforma??o (LEG)
| Universidade Federal do Paran? (UFPR)
| 
| _______________________________________________
| 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