Romain Francois, Professional R Enthusiast - inlineIndependant statistical/R consultant2013-03-24T15:53:22+01:00Romain Francoisurn:md5:2cdb21a695f56bfe2b31ee2133c51b42Dotclearinline 0.3.6urn:md5:596f071d9eb7897014db27602abbbd672010-07-30T15:34:00+02:00romain francoisinlineCRANinlineRcpp <p>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 : </p>
<pre>
> 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>
5:
6:
7: // user includes
8:
9:
10: // declaration
11: extern "C" {
12: SEXP file10d63af1( ) ;
13: }
14:
15: // definition
16:
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: }
22:
23:
[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"
</pre>
<p>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!". </p>
<p>This will be especially useful for developing Rcpp, which rely on inline for unit testing</p>inline 0.3.5urn:md5:450d4cd7b29c1d823082c03ea33687bf2010-06-02T11:08:00+02:00romain francoisinlinecplusplusCRANinlineRRcpp <p>The <a href="http://cran.r-project.org/web/packages/inline/index.html">inline</a> 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.</p>
<p>Together with RUnit, inline powers the entire unit test suite of <a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a>. </p>
<p>As agreed with Oleg Sklyar, who maintains inline, we made a few additions to inline to accomodate the needs of the <a href="http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp">Rcpp</a> family of packages. </p>
<h3>cxxfunction</h3>
<p>The main addition is <a href="http://finzi.psych.upenn.edu/R/library/inline/html/cxxfunction.html">cxxfunction</a> which is very similar to <a href="http://finzi.psych.upenn.edu/R/library/inline/html/cfunction.html">cfunction</a>, except that it only focuses on C++ code using the <a href="http://finzi.psych.upenn.edu/R/library/base/html/Foreign.html">.Call</a> calling convention. <a href="http://finzi.psych.upenn.edu/R/library/inline/html/cxxfunction.html">cxxfunction</a> 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
<a href="http://dirk.eddelbuettel.com/code/rcpp.html">Rcpp</a> defines an inline plugin that takes care of all the details (find the Rcpp include path, link against the Rcpp user library, etc ...) </p>
<p>Here is an example, from the <a href="http://finzi.psych.upenn.edu/R/library/inline/html/cxxfunction.html">cxxfunction</a> 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)</p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/inline/cxx.R.html" width=500 height=100></iframe>
<p>Here is an example using the plugin from the next version of <a href="http://dirk.eddelbuettel.com/code/rcpp.armadillo.html">RcppArmadillo</a></p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/inline/cxxarma.R.html" width=500 height=120></iframe>
<h3>package.skeleton</h3>
<p>Another addition to inline concerns the <a href="http://finzi.psych.upenn.edu/R/library/utils/html/package.skeleton.html">package.skeleton</a>. We've made it S4 generic in inline and defined methods for the <strong>CFunc</strong> and <strong>CFuncList</strong> classes. In short, this allows to prototype some code using inline and quickly dump the code into a proper package</p>
<p>For example, here we make two functions using cxxfunction and then generate a package skeleton directly from them</p>
<iframe src="http://romainfrancois.blog.free.fr/public/packages/inline/packskel.html" width=500 height=190></iframe>
<p>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 ... </p>
<h3>getDynLib</h3>
<p><strong>getDynLib</strong> 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</p>