I am a big fan of Splus and R and I am often recommending these systems to colleagues. One of the many reasons I like the programs is their very active users’ communities. If one runs into trouble, there are always other users willing to help. Nevertheless, a while ago I started noticing a disturbing trend: one of the Splus/R language demigods was becoming increasingly arrogant—and rude—in his replies to fellow posters. What was even more surprising is that nobody seemed to care. As Eric Hoffer said:
Rudeness is the weak man’s imitation of strength.
I was uncomfortable, but the situation was below my ‘annoyance threshold’ until this reply to this post. I was so annoyed that submitted this message, which generated an interesting discussion that resulted in a ‘lawyer-style’ apology from the offender. The interesting thing is that—after my post—I received several personal emails from people that where equally uncomfortable with the situation, but felt uneasy challenging the ‘powers that be’. This seems to be yet another example of the issues faced by internet communities, where a few individuals can easily damage the quality of communication in a forum.
I think that after this experience we will go back to a much more respectful and welcoming email list, so people are not afraid of posting simple questions and being flamed in the process.
Checking the server logs I have discovered that many people that arrive at my posts on calling VB from R are, in fact, looking for the reverse. I have never done any programming calling R from VB; however, while I was looking for COM clients for R I also found information on COM servers. OmegaHat lists RDCOMServer as a package that exports S (or R) objects as COM objects in Windows. It provides examples on using VB, Python and Perl to call R code.
Another option is Thomas Baier’s R(D)COM Server, which is provided with examples in the same languages used by RDCOM Server.
After yesterday’s experience calling other software from R, I continued working to connect to my DLL. I first registered my DLL as a COM server in windows typing in the command line:
Then I had a look at my DLL using the SWinTypeLibs library, typing in R:
library(SWinTypeLibs) wood <- LoadTypeLib("c:\\data\\rconnect\\growthmodels.dll") getTypeLibTypes(wood) DLLFuncs <- getFuncs(wood[]) DLLElements <- getElements(wood[])
The command getTypeLibTypes(wood) showed that the DLL contained _cPlantationModels (of type dispatch) and cPlantationModels (of type coclass). That is why I then continued working with wood[], of type dispatch.
After that I needed help from Tim. He had compiled the DLL leaving the class module cPlantationModels with an instancing of type 5 (multiUse), making it available for outside users. Connecting to the library was relatively straightforward with Tim’s help:
library(RDCOMClient) growthmod <- COMCreate("growthmodels.cPlantationModels") growthmod$ModelCreate(30,11,8,4,0,25,5,5,1000,0,1,2,0,1) standvol <- growthmod$TreeValue(20) growthmod$ModelDestroy()
This code loaded the RDCOM client library, created a connection to the DLL, instantiated a growth model with starting values, evaluated the model and destroyed the instantiation. Now we are ready to start testing the models from inside R.
PS. 2005-02-03. I have added information on COM servers for R in my post Calling R from Visual Basic (link to Quantum Forest).
I want to test a series of growth models that are part of a DLL written in Visual Basic. Although I could write several pieces of code in VB to test the library, I will try to access it from R. In this way I can run simulations and then process the results from within a statistical package.
I obtained the RDCOM client and the SWinTypeLibs facilities from the Omega Hat Project for Statistical Computing. If you are running R 2.0 you should get the latest compilations from here (RDCOMClient_0.8-1.zip, 11-Oct-2004, 12:08, 433K and SWinTypeLibs_0.2-1.zip, 11-Oct-2004, 12:09, 147K).
It is possible to learn about the classes, methods, parameters and return types of a COM server using the SWinTypeLibs library. Once we have learn about the server, we can access it using the RDCOMClient (this is explained in this presentation in PDF format, 50KB). For example:
library(RDCOMClient) ie = COMCreate("InternetExplorer.application") ie[["Visible"]] <- TRUE ie$Navigate2("http://www.uncronopio.org/quantum/")
will load the library, connect to Internet Explorer, display the window and point the browser to Quantum Forest. An example using Excel would be:
exc <- COMCreate("Excel.Application") exc[["Visible"]] <- TRUE books <- exc[["Workbooks"]] books$Add() actsheet <- books[][["ActiveSheet"]] myrange <- actsheet$Range("A1:C10") myrange[["Value"]] <- asCOMArray(matrix(rnorm(30, 10, 3)))
This will connect to Excel, show the program, get a list of workbooks, add one, get which sheet is active, define a range and fill it with N(0,1) random numbers.
I will continue exploring the package to see if I can connect to my own DLL.
I was looking for a good free ‘point and click’ statistical software for some colleagues of mine. Although I did not find anything even close to what I was looking for—sort of R with menus—at least I found a nice R interface. JGR (pronounced like Jaguar) provides object browser, data and code editors (both with syntax highlighting), help browser and package manager.
I can see tools like the package manager evolving into tools for specific analyses like linear models, descriptive statistics, etc. I hope these guys can pull it off.
One of the reasons I have revisited R is that it provides access to a large range of cutting edge statistical procedures. This software project has a critical mass of users—actually, a great users’ community—that implies early adoption of statistical techniques.
I have struggled for a while with smoothing splines, and what better way of learning their use than playing with some data. Years ago I met Rod Ball in Forest Research (Rotorua, New Zealand), where he always made useful comments during my PhD presentations. The world is a small place, and now I am playing with Rod’s lmeSplines library, which allows fitting smoothing splines using lme. The library can be downloaded from CRAN (Comprehensive R Archive Network, see contributed packages under your operating system) and there is an introduction to its use in R news (PDF file 1.3MB).
PS 2004-11-18. I was contacted by a fellow ASReml user, worried because I was not using ASReml’s splines facilities. I want to make clear that there is no problem whatsoever with splines in ASReml. It is just that I am trying many alternative models (including non-linear ones), data manipulation and graphics with a dataset of squid behaviour, and doing everything inside one piece of software it is easier.