Accessing a COM Server from R

Microsoft have recently added support for R to their Visual Studio 2015 development environment. R is a programming language for statistical and graphical programming that is widely used by statisticians and data miners.

To use R with Visual Studio, you need to download and install R Tools for Visual Studio and Microsoft R Open. These will work fine with the Community Edition of Visual Studio 2015. In addition to support for R, R Tools for Visual Studio adds a debugger and Intellisense, as well as support for multi-threading and cluster computing.

It would be useful if R was able to interface with other active applications, for example with COM. Unfortunately at the moment, R Tools for Visual Studio does not add any ability in this area. There is the RDCOMClient package from Omegahat. Unfortunately the documentation and installation instructions are old, incomplete, or simply wrong. The source code is also available, but I could not get it to build.

I did manage to eventually get it to install with R Tools for Visual Studio, using the following two lines:

Very simple! Omegahat’s own installation instructions do not work because they refer to their own repository. However, the standard CRAN repository works just fine.

Here are some usage examples, working with Excel:

The excel.link package is available specifically for Excel communication, and should be more convenient. However, Excel makes a useful demonstration of RDCOMClient’s COM interface.

The following documentation is also available:

The RDCOMServer package can be used if you wish to create COM server objects within R. External applications can then call these. For example, you might want to encapsulate a data analysis routine in a COM server that other applications can then call.

The article, Statistically Valid Interpolation with R, uses RDCOMClient along with the sp and gstat packages to krige input point data (Ogwalla aquifer depths) in R and then use it to create a gridded layer in Caliper Maptitude.

Leave a Reply