private static void Run(RConnection c) { string filePath = "C:/Users/DarkBlue/Google Drive/onlinedatalab/source/dummy data.csv"; string scriptPath = @"C:\OnlineDataLab\Scripts\input.R"; REngine.RunScript(c, scriptPath); Sexp r = c.TryEval(string.Format("processInput(\"{0}\")", filePath)); Console.WriteLine(r.AsDictionary); //var x = c.Eval("R.version.string"); //Console.WriteLine(x.AsString); //Task.Factory.StartNew(() => //{ // //using (var s1 = RConnection.Connect(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }))) // //{ // string filePath = "C:/Users/DarkBlue/Google Drive/onlinedatalab/source/dummy data.csv"; // string scriptPath = @"C:\OnlineDataLab\Scripts\input.R"; // c.TryVoidEval(File.ReadAllText(scriptPath)); // c.TryVoidEval("processInput <- function(inputFilePath){ uploaddata < -read.csv(inputFilePath);outputdata < -toJSON(uploaddata[1:20,]);allchoices < -names(uploaddata);return (list(\"uploaddata\" = uploaddata, \"outputdata\" = outputdata, \"allchoices\" = allchoices));}"); // //c.VoidEval(string.Format("uploaddata <- read.csv(\"{0}\")", filePath)); // var data = c.Eval("test()"); // Console.WriteLine(data.AsList); // //s1.Shutdown(); // //} //}).Wait(); //using (var s = RConnection.Connect(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }))) //{ // // Generate some example data // var x = Enumerable.Range(1, 20).ToArray(); // var y = (from a in x select (0.5 * a * a) + 2).ToArray(); // // Build an R data frame // var d = Sexp.MakeDataFrame(); // d["x"] = Sexp.Make(x); // d["y"] = Sexp.Make(y); // s["d"] = d; // // Run a linear regression, obtain the summary, and print the result // s.VoidEval("linearModelSummary = summary(lm(y ~ x, d))"); // var coefs = s["linearModelSummary$coefficients"]; // var rSquared = s["linearModelSummary$r.squared"].AsDouble; // Console.WriteLine("y = {0} x + {1}. R^2 = {2,4:F}%", coefs[1, 0], coefs[0, 0], rSquared * 100); // // Now let's do some linear algebra // var matA = new double[,] { { 14, 9, 3 }, { 2, 11, 15 }, { 0, 12, 17 }, { 5, 2, 3 } }; // var matB = new double[,] { { 12, 25 }, { 9, 10 }, { 8, 5 } }; // s["a"] = Sexp.Make(matA); // s["b"] = Sexp.Make(matB); // Console.WriteLine(s["a %*% b"].ToString()); //} }