VB6 to C#‎ > ‎VB6 to C# Downloads‎ > ‎

Calling R From CSharp DotNet

If you've been looking for a way to call R from your C# and .NET code, this sample project will show you how to interface to the mt4r.dll to access the R terminal. The cMT4R interface is an easy way to gain access to the R statistical computing environment from C# and .NET.

A bit of history: MT4R is a project that allows access to R through a Windows DLL interface that interfaces with the R terminal. The interface was originally written for access from Metatrader to R. However, I quickly realized that mt4R.dll could also be a useful tool to link other programming environments such as C# .NET to R, as well as VB6 to R. I created a simple class that translates and adapts the Metatrader interface found in mt4R.mqh so that C# and DotNet users may access the mt4R dll and thus access the power of the R statistical computing environment from C# / .NET.
  1. Download the demo project (below) and change the default R path in the cMT4R class, Start_R method to match your actual R installation.
  2. Download the mt4r.dll found at the R for Metatrader site and place it in your \Windows\System\ directory.
  3. Run the demo project to verify that you can link C# to perform calculations in R, and transfer data back and forth.
  4. Study the mt4R documentation to understand how it works.
  5. Read the comments in the code (found in cMT4R).
If you have any questions, comments or suggestions for cMT4R, please post a comment. Enjoy!

Attached is a zipped project folder containing TestMT4R, which shows how to use cMT4R. You may freely add cMT4R to your C# and .NET projects.
ċ
TestMT4R.zip
(68k)
Patrick White,
Aug 14, 2012, 7:03 PM
Comments