You are here: TWiki > Quantlib Web > JoesNotes > RSwig r25 - 05 Jun 2006 - 05:07 - Main.joe


Start of topic | Skip to actions
Here are design note for RSwig. An experimental interface between R and Swig.

The patches are attached to this page and are built against CVS (although they should apply cleamly to most recent versions of SWIG.)

Also attached is the file "make.out" which is the current unit test report.

This is based on the work http://www.omegahat.org/RSWIG/ by Duncan Temple Lang.

See RSwigBlog for current details.

If you are interesting in working this this please contact Joseph Wang. This is part of a general project to understand warrant pricing on the Shanghai exchange.

  • Collection encapsulation - The collection classes are implemented the same as any other C++ class. What I'd like to do is to do all of the type conversion between the C++ class and the native classes in S.

Purpose of RSWIG

The motivation for this work is to for academic research I am doing on derivatives on the Shanghai stock market. I'm always interested in hearing news, opinions, and job openings about Chinese derivatives. See my Home Page

-- JosephWang - 27 Feb 2006

Design notes

Basic philosophy is to have SWIG create a minimal wrapper around C++ and then to do as much as possible in R.

Class implementation

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

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.

For enumerations to work, the enum has to be defined in the .i file. There are problems if the .i references an enumeration which is not in the .i file through a typedef. RSwigDocumentation

Indexes

getitem and setitem use C++ conventions (i.e. zero based indices). [<- and [ are overloaded to allow for R syntax (one based indices and slices)

Need to think of a way of getting a function to trigger a wrapper call. I don't want so much stuff in the cxx file.

Arrays

  • RSwig compiles most of the SWIG unit tests. It should be able to convert transparently between R vectors and C arrays (although you really should be using C++ STL vectors).

Notes

  • There seems to be a messy conflict between S3 and S4 dispatching which turned out to be due to a R bug. You need to execute the command cacheMetaData(1) after you load the R-SWIG wrappers to get it to incorprate the S4 methods.

Short Term TODO

  • Figure out list <-> vector conversion

Long Term TODO

See the list of RSwigTodo

  • Fix what I've broken - Array and C mode
  • Try to make the C++ objects work with garbage collection with smart pointers.

* Integrate this with sampledcurve (this is more a quantlib project than a swig one)

toggleopenShow attachmentstogglecloseHide attachments
Topic attachments
I Attachment Action Size Date Who Comment
elsebz2 rswig.tar.bz2 manage 85.5 K 08 Jun 2006 - 14:18 Main.joe Add copyToR mechanism
elseout make.out manage 558.3 K 19 May 2006 - 00:04 Main.joe It compiles
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r25 < r24 < r23 < r22 < r21 | More topic actions
Copyright ©2001-2008 by the contributors of Quantlib. Content released under the Modified BSD License.