Romain Francois, Professional R Enthusiast

To content | To menu | To search

Tag - inline

Entries feed - Comments feed

Wednesday, December 1 2010

RcppGSL 0.1.0


We released the first version of our RcppGSL package. RcppGSL extends Rcpp to help programmers code with the GNU Scientific Library (GSL).

The package contains template classes in the RcppGSL namespace that act as smart pointers to the associated GSL data structure. For example, a RcppGSL::vector<:double> object acts a smart pointer to a gsl_vector*. Having the pointer shadowed by a smart pointer allows us to take advantage of C++ features such as operator overloading, etc ... which for example allows us to extract an element from the GSL vector simply using [] instead of GSL functions gsl_vector_get and gsl_vector_set

The package contains a 11 pages vignette that explains the features in details, with examples. The vignette also discusses how to actually use RcppGSL, either in another package (preferred) or directly from the R prompt through the inline package.

Friday, July 30 2010

inline 0.3.6

I released inline 0.3.6 yesterday. This is a minor release which gives better R level errors when there is a compiler error. For example :

> tryCatch( cxxfunction( , 'int x = 3 ; x+ ; return R_NilValue ; ' ), error = function(e) print(e$message))
file10d63af1.cpp: In function ‘SEXPREC* file10d63af1()’:
file10d63af1.cpp:18: error: expected primary-expression before ‘;’ token
make: *** [file10d63af1.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
  1: // includes from the plugin
  2: #include <R.h>
  3: #include <Rdefines.h>
  4: #include <R_ext/Error.h>
  7: // user includes
 10: // declaration
 11: extern "C" {
 12: SEXP file10d63af1( ) ;
 13: }
 15: // definition
 17: SEXP file10d63af1(  ){
 18: int x = 3 ; x+ ; return R_NilValue ;  
 19: Rf_warning("your C++ program does not return anything"); 
 20:  return R_NilValue ; 
 21: }
[1] "Compilation ERROR, function(s)/method(s) not created! file10d63af1.cpp: In function ‘SEXPREC* file10d63af1()’:\nfile10d63af1.cpp:18: error: expected primary-expression before ‘;’ token\nmake: *** [file10d63af1.o] Error 1"

The compile error is part of the message of the R error, with previous versions, the R error always had the same message "Compilation ERROR, function(s)/method(s) not created!".

This will be especially useful for developing Rcpp, which rely on inline for unit testing

Wednesday, June 2 2010

inline 0.3.5

The inline package is an amazing, yet simple, package for R. It allows to dynamically (within the R session) define R functions and S4 methods with inlined C/C++/Fortran code.

Together with RUnit, inline powers the entire unit test suite of Rcpp.

As agreed with Oleg Sklyar, who maintains inline, we made a few additions to inline to accomodate the needs of the Rcpp family of packages.


The main addition is cxxfunction which is very similar to cfunction, except that it only focuses on C++ code using the .Call calling convention. cxxfunction uses a plugin system allowing other packages to control the code that is generated before compilation, environment variables, etc ... For example, the next version of Rcpp defines an inline plugin that takes care of all the details (find the Rcpp include path, link against the Rcpp user library, etc ...)

Here is an example, from the cxxfunction help page using the Rcpp plugin (this will only work with the next version of Rcpp, because the current version does not know about this)

Here is an example using the plugin from the next version of RcppArmadillo


Another addition to inline concerns the package.skeleton. We've made it S4 generic in inline and defined methods for the CFunc and CFuncList classes. In short, this allows to prototype some code using inline and quickly dump the code into a proper package

For example, here we make two functions using cxxfunction and then generate a package skeleton directly from them

Furthermore, the package.skeleton methods are aware of the plugin system, which allows plugin to have some control of additional steps involved in making the package skeleton, such as Makevars files, etc ...


getDynLib has been introduced in this version of inline to grab a reference to the dynamic library associated with a package, a function (CFunc object) generated by inline, or a set of functions (CFuncList object) generated by inline