First steps of Survo R

Posted by Reijo Sund Reijo Sund  
Report Content as Inappropriate
The Muste project was suggested in February 2009 by Reijo Sund. The main motivation for the project was that certain unique or otherwise useful properties of Survo were not available in the form of an open source multiple platform software. As the R project had become very popular, and offered an appeling environment for implementing open source statistical software for multiple platforms, it was a natural choice to test how it would be possible to produce Survo-look-a-like functionality in this environment.

It quickly turned out that the Tcl/Tk package, that is a part of base R, would allow the implementation of the editorial approach. More precicely, so called text widget made it possible to create a window containing text and control it appropriately. The first step was to develop a simplified look-a-like version of the Survo editor using R-language. It was also quite simple to include some commands such as LOAD and SAVE as well as a few matrix operations to be used from the editor. It also turned out that it was possible to run real Survo-modules directly from the editor by calling the corresponding exe-files (with the help of Wine in the non-MS-Windows environments).

One of the very first versions of Muste running
One of the very first versions of Muste running.

Such tests were so promising that the next step was to test if it would be possible to use the C source code of Survo in the Muste-project. Professor Seppo Mustonen (the developer of Survo) kindly provided all required source code of Survo for such tests, starting with the Survo library functions and editorial arithmetics.

It was rather straightforward to compile the needed parts of the source code of Survo with GCC and then call the produced stand-alone executable from the look-a-like editor running in R. As R allows the use of C sources in the packages, it was also quite easy to implement an exact imitation of the editorial arithmetics of Survo as a part of an actual R-package (i.e. the C code is called from the package's dynamically linked library when needed). Also few other modules were tested, and the conversion required only minor changes to the original Survo C sources.

The next step was to remove the look-a-like editor programmed in R and replace it with the real Survo editor programmed in C. There were some challenges for the implementation, because the I/O-functions had to be reprogrammed to work with Tcl/Tk that was called inside R that run the package compiled from the C sources. Fortunately, the communication between R-level objects and compiled C code works well.

However, especially the screen updating required some tricks, because the strategy to call R function from the C code that then called Tcl/Tk function was too slow if there was a need to produce a lot of small updates. It turned out that the direct call to Tcl/Tk-packages dotTcl()-function was enough to speed up the process (i.e. the idea was to avoid unnecessary R-parsing). The calling of non-registered C-function from the other package required the use of R function R_FindSymbol() (instead of the recommended R_GetCCallable()), and in order to call the function dotTcl() the parameters had to be manually converted to R form (i.e. to LISP-style list).

Another challenge has been to implement an event loop inside the C code that also detected the keyboard and mouse events of Tcl/Tk. The required functionality was obtained by using tcl commands update and after to create a wait-function, and by programming an appropriate event handler so that all keyboard and mouse events recorded also the event time and type that could be peeked using the C-code.

Please see the paper Muste - the R implementation of Survo published in the yearbook of Finnish Statistical Society for more information about the first steps of Muste project.

In may 2013 Muste project had reached such a mature state that its name was changed to: Survo R.