I'm wondering if it is possible to call .NET functions from R, via a COM call.
The library rcom
allows calls to COM objects, so this should be possible, in theory, for any .NET assembly that is exposed as a COM object.
To keep it simple, I'll see if I can call the .Reverse()
function in System.Text
, which is exposed by default as a COM object from the .NET framework.
This is what I have tried so far:
I obtained a list of ProgID's in my system (see link to C# code). Here is a list of the relevant ProgIDs in my system:
---start list of COM ProgID entries--- <snip> System.SystemException -> mscoree.dll System.Text.ASCIIEncoding -> mscoree.dll System.Text.StringBuilder -> mscoree.dll System.Text.UnicodeEncoding -> mscoree.dll System.Text.UTF7Encoding -> mscoree.dll System.Text.UTF8Encoding -> mscoree.dll <snip> ---end list---
This R code loads a .NET .dll exposed as a COM object:
library('rcom') x <- comCreateObject("System.Text.ASCIIEncoding")
Its definitely finding the COM object:
x attr(,"class") 1 "COMObject"
My question is - how do I call the
.Reverse()
function within this COM object?
Update
In .NET, the call would be:
string x = "hello".Reverse();
So, in R, the call would be?
Update
For an example of R calling C#, see R calls C# in Embedding R in Applications on Windows on slide 61.
Note that ProgId
is ProjectName.ClassName
from .NET class.