|
Start of topic | Skip to actions
This is a holding area for R documentation
SWIG and RR is a GPL'ed open source statistical and plotting environment. Information about R can be found at www.r-project.org. The R binding are under active development and are extremely experimental. Not all features have been implemented and the API is not stable.BugsCurrently the following features are not implemented or broken:
Using R and SWIGTo use R and SWIG in C mode, execute the following commands where example_func.c is the name of the file with the functions in them swig -r -o example,c example.i PKG_LIBS="example_func.c" R CMD SHLIB example.c swig -c++ -r -o example.cpp example.i PKG_LIBS="example_func.cxx" R CMD SHLIB example.cpp The commands produce two files. A dynamic shared object file called example.so and an R wrapper file called example_wrap.S. To load these files, start up R and type in the following commands
dyn.load('example.so')
source('example_wrap.R')
save(list=ls(all=TRUE),file="example.RData")
load(file="example.RData")
dyn.load('example.so')
General policyThe 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.Language conventionsgetitem and setitem use C++ conventions (i.e. zero based indices). [<- and [ are overloaded to allow for R syntax (one based indices and slices)C++ classesC++ 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.Enumerationsenumerations 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. | ||||