Romain Francois, Professional R Enthusiast

To content | To menu | To search

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