1

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?

1
  • 2
    Given your specific example you seem to be dealing with a Shiny app. There’s probably a simpler way of specifically invoking Shiny apps from C# than there is for generic R code. That said, there’s the “R.NET” library, which does pretty much exactly what you want. Commented Sep 25, 2018 at 15:44

2 Answers 2

1

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");
Sign up to request clarification or add additional context in comments.

Comments

0

You can invoke the script file with your application.

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.