This project is read-only.

Calling external LiB Function

Feb 14, 2013 at 11:12 AM
i want to use randIndex function from flexclust library but i failed to use this..
this function working fine in R environment. how i can use this function in C# code
Feb 18, 2013 at 11:23 AM

Can you provide precise information as to what fails, preferably as a stand-alone small C# program.

Feb 20, 2013 at 10:47 AM
        REngine engine = REngine.GetInstanceFromID("RDotNet");

        if (engine == null)
            engine = REngine.CreateInstance("RDotNet", new[] { "-q" });

        // .NET Framework array to R vector.
        IntegerVector group1 = engine.CreateIntegerVector(classes);
        engine.SetSymbol("classes", group1);

        IntegerVector group2 = engine.CreateIntegerVector(clusters);
        engine.SetSymbol("clusters", group2);

        double result = engine.EagerEvaluate("randIndex(tab,correct=FALSE)").AsNumeric().First();


where randIndex is function of external Library named "flexclust"
Feb 28, 2013 at 1:36 AM
Your program is not stand-alone, and classes and clusters are undefined. Also unknown is where things fail.
All I can say is that an example from the randIndex documentation works as expected. This is running on a recent code checkout of R.NET and highly likely to run on R.NET 1.5 as well.
            var envPath = Environment.GetEnvironmentVariable("PATH");
            var rBinPath = @"F:\bin\R\bin\x64";
            Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
            using (REngine engine = REngine.CreateInstance("RDotNet"))
                engine.Evaluate("g1 <- sample(1:5, size=1000, replace=TRUE)");
                engine.Evaluate("g2 <- sample(1:5, size=1000, replace=TRUE)");
                engine.Evaluate("tab <- table(g1, g2)");
                double result = engine.Evaluate("randIndex(tab,correct=FALSE)").AsNumeric().First();