user1753377
user1753377

Reputation: 57

Can I execute R code files from within C#?

I have an R source file.

I want to execute the code in that file within my C# app.

The .R file has a function that looks like this:

How can I execute the .R file from my console app and pass in the parameters for the function?

Upvotes: 1

Views: 223

Answers (2)

fourwhey
fourwhey

Reputation: 530

You can invoke the script file with your application.

http://jmp75.github.io/rdotnet/

engine.Evaluate("source('c:/src/path/to/myscript.r')");

Upvotes: 0

OMANSAK
OMANSAK

Reputation: 1332

You can use rdotnet(R.NET)

R.NET enables .NET Framework to collaborate with R statistical computing. R.NET requires .NET Framework 4 and native DLLs installed with R environment. You need no other extra installations. Enjoy statistics and programming in your special language with R.

https://archive.codeplex.com/?p=rdotnet

        REngine.SetEnvironmentVariables();
        REngine engine = REngine.GetInstance();
        engine.Initialize();
        //string path = "\HelloWorld.r";
        //engine.Evaluate("source('" + path + "')");
        var x = engine.Evaluate("x <- 1 + 2");

Upvotes: 1

Related Questions