R is a GPL'ed open source statistical and plotting environment. Information about R can be found at www.r-project.org. The R bindings are under active development. They have been used to compile and run an R interface to QuantLib running on Mandriva Linux with gcc. The R bindings also work on Microsoft Windows using Visual C++.
Currently the following features are not implemented or broken:
To use R and SWIG in C mode, execute the following commands where example.c is the name of the file with the functions in them
swig -r example.i PKG_LIBS="example.c" R CMD SHLIB example_wrap.c
The corresponding comments for C++ mode are
swig -c++ -r -o example_wrap.cpp example.i PKG_LIBS="example.cxx" R CMD SHLIB example_wrap.cpp
Note that R is sensitive to the name of the file and to the file extension in C and C++ mode. The name of the wrapper file must be the name of the library. Also in C++ mode, the file extension must be .cpp rather than .cxx for the R compile command to recognize it.
The commands produces two files. A dynamic shared object file called example.so, or example.dll, and an R wrapper file called example.R. To load these files, start up R and type in the following commands
dyn.load(paste("example", .Platform$dynlib.ext, sep="")) source("example.R") cacheMetaData(1)
These two files can be loaded in any order
source('BigFile.R') save(list=ls(all=TRUE),file="BigFile.RData", compress=TRUE) q(save="no")This will generate a compiled R file called BigFile.RData that will save a large amount of loading time.
The general policy of the module is to treat the C/C++ as a basic wrapping over the underlying functions and rely on the R type system to provide R syntax.
getitem and setitem use C++ conventions (i.e. zero based indices). [<- and [ are overloaded to allow for R syntax (one based indices and slices)
C++ objects are implemented as external pointer objects with the class being the mangled name of the class. The C++ classes are encapsulated as an SEXP with an external pointer type. The class is the mangled name of the class. The nice thing about R is that is allows you to keep track of the pointer object which removes the necessity for a lot of the proxy class baggage you see in other languages.
enumerations are characters which are then converted back and forth to ints before calling the C routines. All of the enumeration code is done in R.