This project is read-only.


Jul 11, 2012 at 10:09 PM
Edited Jul 11, 2012 at 10:36 PM

I think is a very good tool and if with more document then the better!

I tried to do a simple test for the with c#,, and it runs ok the first time, but then will get error and only after I restart the visual studio 2010 I can continue to run.

the error info is:

{"External component has thrown an exception."}
   at RDotNet.Internals.DirectNativeMethods._setup_Rmainloop()
   at RDotNet.Internals.DirectNativeMethods.setup_Rmainloop()
   at RDotNet.REngine..ctor(String id, OutputMode output, CharacterDeviceAdapter adapter)
   at RDotNet.REngine.CreateInstance(String id, OutputMode output, ICharacterDevice device)
   at RDOTNETTest._Default.Button1_Click(Object sender, EventArgs e) in C:\Projects\RDOTNETTest\RDOTNETTest\RDOTNETTest\Default.aspx.cs:line 33
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
TargetSite: {Void _setup_Rmainloop()}

Can anyone give me some hint on solution of this issue? Thanks

the following is my complete code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RDotNet;

namespace RDOTNETTest
    public partial class _Default : System.Web.UI.Page

        private REngine engine;
        private String ErrMsg;
        private String RResultStr;

        protected void Page_Load(object sender, EventArgs e)

        protected void Button1_Click(object sender, EventArgs e)
            string rhome = System.Environment.GetEnvironmentVariable("R_HOME");
            if (string.IsNullOrEmpty(rhome))
                 rhome = @"C:\R\R-2.15.0";

            System.Environment.SetEnvironmentVariable("R_HOME", rhome);
            System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + rhome + @"\bin\i386");
          //the following line of code would crash the application if click the button more than once
            engine = REngine.CreateInstance("RDotNet");

            using (engine)
                // .NET Framework array to R vector.
                NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
                engine.SetSymbol("group1", group1);
                // Direct parsing from R script.
                NumericVector group2 = engine.EagerEvaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();

                // Test difference of mean (Student's t-test) and get the P-value.
                GenericVector testResult = engine.EagerEvaluate("t.test(group1, group2)").AsList();
                double p = testResult["p.value"].AsNumeric().First();
                RResultStr += string.Format("Group1: [{0}]", string.Join(", ", group1.Select(value => value.ToString())));
                RResultStr += System.Environment.NewLine + string.Format("Group2: [{0}]", string.Join(", ", group2.Select(value => value.ToString())));
                RResultStr += System.Environment.NewLine + string.Format("P-value = {0:0.000}", p);
                TextBox1.Text += RResultStr;