This project is read-only.

Unable to evaluate 'stats library' functions in ASP .NET

Oct 23, 2013 at 7:18 AM
Hi all,

I am currently using R.Net 1.5.5 in my ASP .Net application.
I am able to use basic functions with no issues, but I can't use the aov() function.
I have used the exact same code in a C# console application and it evaluates fine.

Code I have in both applications:
public static class RStats
    {
        public static readonly REngine Engine;
        private static string _rpath = @"C:\Program Files\R\R-3.0.0\bin\x64;C:\Program Files\R\R-3.0.0\bin";

        private static REngine NewInstance()
        {
            if (Environment.Is64BitProcess) _rpath = _rpath.Replace("i386", "x64");
            var path = Environment.GetEnvironmentVariable("PATH");
            if (path == null || !path.Contains(_rpath)) path += ";" + _rpath;
            Environment.SetEnvironmentVariable("PATH", path);
            var engine = REngine.CreateInstance("RDotNet");
            engine.Initialize();
            return engine;
        }

        public static IList<string> Test()
        {
            using (var eng = NewInstance())
            {
                var numvec = eng.CreateNumericVector(new[] { 0.0, 1.2, 5.1, 6.2 });
                eng.SetSymbol("Grades", numvec);
                var unitvec = eng.CreateCharacterVector(new[] { "one", "one", "two", "two" });
                eng.SetSymbol("Units", unitvec);
                eng.Evaluate("Frame <- data.frame(Grades,Units)");
                eng.Evaluate("Analysis <- aov(Grades~Units, data=Frame)");
                var myret = ReadDataFrame("Frame", eng).ToList();
                myret.AddRange(ReadLanguage("Analysis", eng));
                return myret;
            }
        }
......
I always get a "ParseException: Error in the application" on the "Analysis <- aov(Grades~Units, data=Frame)" line.
However this code works perfectly in a console application.

Any help would be greatly appreciated!
Oct 24, 2013 at 1:17 PM
I know little of ASP.NET, and am of limited help. There seems to be a few posts reporting issues with an ASP.NET deployment.

An REngine should be created and initialized only once during a process lifetime https://rdotnet.codeplex.com/workitem/54. With your code, you are likely to create /initialize REngine several times.

the post from stefano22 at https://rdotnet.codeplex.com/discussions/462947 seems to have a single pattern to make sure REngine is initialized only once. However despite he still has issues.
Oct 28, 2013 at 3:36 AM
Thanks for the reply, jperraud.

I definitely only have one instance initialised at a time. At this stage I've had to give up on trying to implement R.Net in my ASP .Net application.
It appears stefano22 and I have the same issue. It seems only the base package/library can be evaluated from ASP .Net projects. Non-base functions such as t.test, aov, anova, cor and cov raise a ParseException. If I encounter a solution, I'll definitely return with the results.

Thanks,

Carl