Click here to Skip to main content
14,428,340 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

I am using RDotNet to execute RScript from my C# program. Is there any .net library available other than RDotNet. RDorNet is always causing the problem.

Regards,
Ratheesh

What I have tried:

I am using RDotNet to execute RScript from my C# program
Posted
Updated 9-Jul-17 20:12pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Another thing you can do is run the R code in process you create just for that task. See this code sample written by Jake Drew on stackoverflow:

public static string RFromCmd(string rCodeFilePath, string rScriptExecutablePath, string args)
    {
            string file = rCodeFilePath;
            string result = string.Empty;

            try
            {

                var info = new ProcessStartInfo();
                info.FileName = rScriptExecutablePath;
                info.WorkingDirectory = Path.GetDirectoryName(rScriptExecutablePath);
                info.Arguments = rCodeFilePath + " " + args;

                info.RedirectStandardInput = false;
                info.RedirectStandardOutput = true;
                info.UseShellExecute = false;
                info.CreateNoWindow = true;

                using (var proc = new Process())
                {
                    proc.StartInfo = info;
                    proc.Start();
                    result = proc.StandardOutput.ReadToEnd();
                }

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("R Script failed: " + result, ex);
            }
    }
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100