static void Main(string[] args) { REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); // REngine requires explicit initialization. // You can set some parameters. engine.Initialize(); // .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.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); // Test difference of mean and get the P-value. GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); double p = testResult["p.value"].AsNumeric().First(); Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); Console.WriteLine("P-value = {0:0.000}", p); // you should always dispose of the REngine properly. // After disposing of the engine, you cannot reinitialize nor reuse it engine.Dispose(); }
private void mainForm_Load(object sender, EventArgs e) { Engine = REngine.GetInstance(); Engine.Evaluate(string.Format("db <- dbConnect(SQLite(),'{0}')", dbfile.Replace("\\", "/"))); InitCols(); }
public MainWindow() { InitializeComponent(); // There are several options to initialize thengine, but by default the following suffice: engine = REngine.GetInstance(); engine.Initialize(); }
public static List <string> CreateCharacterVar(string svarname, string svalue) { try { REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); CharacterVector charVec = engine.CreateCharacter(svalue); engine.SetSymbol(svarname, charVec); List <string> lerrmsg = new List <string> { "\nCreated R variable named " + svarname }; return(lerrmsg); } catch (Exception e) { string errmsg = "\nException encountered while set R variable :" + svarname + "\n"; errmsg += "\nError message :\n" + e.Message + "\n" + e.StackTrace + "\n"; if (e.InnerException != null) { errmsg += "InnerException\n" + e.InnerException.Message + "\n" + e.InnerException.StackTrace + "\n"; } List <string> lerrmsg = new List <string> { errmsg }; return(lerrmsg); } }
public IHttpActionResult Execute() { REngine _engine = REngine.GetInstance(null, true, null, null); SvgGraphicsDevice GraphicsDevice = new SvgGraphicsDevice(new SvgContextMapper(700, 700, SvgUnitType.Pixel, null)); _engine.Initialize(); _engine.Install(GraphicsDevice); RApplication app = new RApplication(_engine); app.DataAccessMethod = "PIAFSDK"; app.Connect("MARC-PI2016"); app.RFunction = "PI Histogram"; app.NumTags = 1; app.Mode = "Interpolated"; var tag1 = "FAC.OAK.Weather-Outside_Temperature-Val.PV"; var tag2 = "FAC.OAK.Weather-Inside_Temperature-Val.PV"; var tag3 = "FAC.OAK.Weather-Inside_Humidity-Val.PV"; var tag4 = "FAC.OAK.Weather-Outside_Humidity-Val.Pv"; var tag5 = "FAC.OAK.Power-Total_Demand_Calc.PV"; app.GetPIData(tag1, tag2, tag3, tag4, tag5, "1-Oct-2012", "1-Nov-2012", "1h"); app.GenerateGhaphic("5", "0", "1", ""); //GraphicsDevice.ClearImages(); //var evaluated = statements.Select(_engine.Evaluate).ToList(); var plots = GraphicsDevice.GetImages().Select(RenderSvg).ToList(); return(Ok(plots)); }
static void Main(string[] args) { DataTable dtb = new DataTable(); dtb.Columns.Add("Column1", Type.GetType("System.String")); dtb.Columns.Add("Column2", Type.GetType("System.String")); DataRow dtr1 = dtb.NewRow(); dtr1[0] = "abc"; dtr1[1] = "cdf"; dtb.Rows.Add(dtr1); DataRow dtr2 = dtb.NewRow(); dtr2[0] = "asdasd"; dtr2[1] = "cdasdasf"; dtb.Rows.Add(dtr2); using (var engine = REngine.GetInstance()) { string[,] stringData = new string[dtb.Rows.Count, dtb.Columns.Count]; for (int row = 0; row < dtb.Rows.Count; row++) { for (int col = 0; col < dtb.Columns.Count; col++) { stringData[row, col] = dtb.Rows[row].ItemArray[col].ToString(); } } CharacterMatrix matrix = engine.CreateCharacterMatrix(stringData); engine.SetSymbol("myRDataFrame", matrix); engine.Evaluate("myRDataFrame <- as.data.frame(myRDataFrame, stringsAsFactors = FALSE)"); engine.Evaluate("str(myRDataFrame)"); } Console.ReadKey(); }
public RdotNetAdapter(IRDotNetConvertor _RDotNetConvertor) { REngine.SetEnvironmentVariables(); engine = REngine.GetInstance(); // imp singletone engine.Evaluate("library(TTR)"); RDotNetConvertor = _RDotNetConvertor; }
private void GoTo() { try { string today = System.DateTime.Today.ToString("yyyy-MM-dd"); string yearAgo = System.DateTime.Today.AddYears(-1).ToString("yyyy-MM-dd"); string rnd = System.Guid.NewGuid().ToString().Replace("-", ""); string filename = "i" + rnd + "__Rimage"; string filenamePNG = filename + ".png"; string rcode = string.Format(@"library(quantmod) stock <- getSymbols('{0}.TW', auto.assign = FALSE,from='{1}') ind <- apply(stock, 1, function(x) all(is.na(x))) stock <- stock[!ind,] chartSeries(stock['{1}::{2}'],name='{3}')" , Stock.Id, "2017-01-03", "2018-01-25", filename); REngine engine = REngine.GetInstance(); engine.Initialize(); //engine.Evaluate(string.Format("png(file='{0}',bg ='transparent',width={1},height={2})", filename, this.pictureBox1.Width, this.pictureBox1.Height)); engine.Evaluate(rcode); //engine.Evaluate("dev.off"); //string path = System.IO.Path.GetFullPath(filenamePNG); //Bitmap image = new Bitmap(path); //pictureBox1.Image = image; label1.Text = string.Format("{0} {1} {2}/{3}", Stock.Id, Stock.Name, iStock, Stocks.Count()); label2.Text = GetStockType(); } catch (Exception e) { } }
private static void Main(string[] args) { string rHome = null; string rPath = null; if (args.Length > 0) { rPath = args[0]; } if (args.Length > 1) { rHome = args[1]; } REngine.SetEnvironmentVariables(rPath: rPath, rHome: rHome); REngine e = REngine.GetInstance(); System.Console.WriteLine(RDotNet.NativeLibrary.NativeUtility.SetEnvironmentVariablesLog); counter = 0; for (int i = 0; i < 6; i++) { TestDataFrameInMemoryCreation(e); } for (int i = 0; i < 6; i++) { TestCallStop(e); } e.Dispose(); }
public void TestConversionToDataFrame() { InMemoryLogger logger; Dictionary <string, string> strMsg; Dictionary <string, string> popTags; LoggerMhTestHelper.CreateTestLogContent(out logger, out strMsg, out popTags); var names = new[] { "Category" , "Message" , "X0" , "X1" , "X2" , "X0_s" , "X1_s" , "X2_s" }; // R does not like column names that start with a numeric char, and prepends X var df = logger.ToDataFrame(); var e = REngine.GetInstance(); e.SetSymbol("TestConversionToDataFrame_df", df); e.SetSymbol("TestConversionToDataFrame_expected_colnames", e.CreateCharacterVector(names)); var b = e.Evaluate("setequal( names(TestConversionToDataFrame_df), TestConversionToDataFrame_expected_colnames )"); Assert.IsTrue(b.AsLogical().First()); e.Evaluate("rm(TestConversionToDataFrame_df, TestConversionToDataFrame_expected_colnames)"); }
public void TestCallMethodWithOutArgument() { const string typeName = "AssemblyForTests.StaticClass"; var engine = REngine.GetInstance(); ClrProxy.LoadAssembly(PATH); var sexp = engine.CreateNumeric(0.0); var arguments = new[] { (long)sexp.DangerousGetHandle() }; Assert.IsTrue(ClrProxy.CallStaticMethod(typeName, "TryGetValue", arguments, arguments.Length, out var results, out var resultsSize)); Assert.AreEqual(2, resultsSize); Assert.IsTrue(engine.CreateFromNativeSexp(new IntPtr(results[0])).AsLogical()[0]); Assert.AreEqual(12.4, engine.CreateFromNativeSexp(new IntPtr(results[1])).AsNumeric()[0]); Assert.IsTrue(ClrProxy.CreateObject("AssemblyForTests.DefaultCtorData", null, 0, out var ptr)); arguments = new[] { ptr }; Assert.IsTrue(ClrProxy.CallStaticMethod(typeName, "TryGetObject", arguments, arguments.Length, out results, out resultsSize)); Assert.AreEqual(2, resultsSize); Assert.IsTrue(engine.CreateFromNativeSexp(new IntPtr(results[0])).AsLogical()[0]); Assert.IsTrue(ClrProxy.GetProperty(results[1], "Name", out var namePtr)); Assert.AreEqual("Out object", engine.CreateFromNativeSexp(new IntPtr(namePtr)).AsCharacter()[0]); }
public static void initializeREngine(string R_HOME, string R_DLL, string R_packages) { if (string.IsNullOrEmpty(R_HOME) || string.IsNullOrWhiteSpace(R_HOME)) { REngine.SetEnvironmentVariables(); } else { REngine.SetEnvironmentVariables(rHome: R_HOME); } StartupParameter myparameter = new StartupParameter() { Interactive = false, Quiet = true, Verbose = false }; if (string.IsNullOrEmpty(R_DLL) || string.IsNullOrWhiteSpace(R_DLL)) { engine = REngine.GetInstance(null, true, myparameter, null); } else { engine = REngine.GetInstance(R_DLL, true, myparameter, null); } // REngine requires explicit initialization. // You can set some parameters. prepareREngine(R_packages); }
public static void TestMethod() { REngine.SetEnvironmentVariables(); // There are several options to initialize the engine, but by default the following suffice: REngine engine = REngine.GetInstance(); // .NET Framework array to R vector. NumericVector testTs = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 }); engine.SetSymbol("testTs", testTs); // Direct parsing from R script. //NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); //auto arima for monthly engine.Evaluate("tsValue <- ts(testTs, frequency=1, start=c(2010, 1, 1))"); engine.Evaluate("library(forecast)"); engine.Evaluate("arimaFit <- auto.arima(tsValue)"); engine.Evaluate("fcast <- forecast(tsValue, h=5)"); var a = engine.Evaluate("fcast <- forecast(tsValue, h=5)").AsCharacter(); NumericVector forecasts = engine.Evaluate("fcast$mean").AsNumeric(); foreach (var item in forecasts) { Console.WriteLine(item); } engine.Dispose(); }
public static byte[] Serialize(string objectName) { var instance = REngine.GetInstance(); var rawVector = instance.Evaluate($"serialize({objectName}, NULL)"); return(rawVector.AsRaw().ToArray()); }
// // GET: /Home/ public ActionResult Index() { REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); engine.Initialize(); 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.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); // Test difference of mean and get the P-value. GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); double p = testResult["p.value"].AsNumeric().First(); Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); Console.WriteLine("P-value = {0:0.000}", p); // you should always dispose of the REngine properly. // After disposing of the engine, you cannot reinitialize nor reuse it engine.Dispose(); return(View()); }
private Q1R() { RDotNet.StartupParameter sp = new StartupParameter(); sp.Interactive = false; sp.Quiet = false; //RDotNet.Devices.ICharacterDevice ic = new RConsola(); RConsola ic = new RConsola(); REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance("", true, sp, ic); if (engine.IsRunning == false) { engine.Initialize(sp, ic, true); } //engine.Evaluate code... string rConsoleMessages = ic.sb.ToString(); REngine.SetEnvironmentVariables(); engine = REngine.GetInstance(); engine.Initialize(); //engine.Evaluate("source('P:/Q1/R/Q1Linear.R')"); }
private void button2_Click(object sender, EventArgs e) { string result; string input; REngine engine; //init the R engine REngine.SetEnvironmentVariables(); engine = REngine.GetInstance(); engine.Initialize(); //input Console.WriteLine("Please enter the calculation"); input = Console.ReadLine(); //calculate CharacterVector vector = engine.Evaluate(input).AsCharacter(); result = vector[0]; //clean up engine.Dispose(); //output Console.WriteLine(""); Console.WriteLine("Result: '{0}'", result); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
private R() { REngine.SetEnvironmentVariables(); engine = REngine.GetInstance(); engine.Initialize(); engine.Evaluate("source('P:/Q1/R/Q1Linear.R')"); }
public void Analyse(List <string> inputTweets) { REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); try { inputTweets.ForEach(x => RCharVector.AddRange(x.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries))); inputTweets.ForEach(x => RCharVector.RemoveAll(y => string.IsNullOrEmpty(y.Trim()))); if (inputTweets.Count > 0) { engine.Evaluate("library('syuzhet')"); CharacterVector gp3 = engine.CreateCharacterVector(RCharVector); engine.SetSymbol("grp3", gp3); engine.Evaluate("grp3"); engine.Evaluate("g <- get_nrc_sentiment(grp3)"); engine.Evaluate("barplot(colSums(prop.table(g[, 3:8])))"); } else { Console.WriteLine("No Tweets found with input data. Please change input data."); } } finally { engine.Dispose(); } }
/// <summary> /// First run of REngine /// </summary> private void Init() { //var path = System.Environment.GetEnvironmentVariable("Path"); //path = @"c:\apps\R\bin;c:\apps\R\bin\x64;c:\Users\Andrej\Documents\R\win-library\3.1" + path; //System.Environment.SetEnvironmentVariable("Path", path); //var path = System.Environment.GetEnvironmentVariable("Path"); //path = @"c:\apps\R\bin;c:\apps\R\bin\x64;" + path; //System.Environment.SetEnvironmentVariable("Path", path); //REngine.(@"C:\APPS\R\bin\x64"); //using (REngine engine = REngine.CreateInstance("RDotNet", new[] { @"R_HOME=c:\APPS\R", @"R_USER=c:\APPS\R" })) rEngine = REngine.GetInstance(); rEngine.Initialize(); //rEngine.Evaluate("install.packages(\"forecast\",dependencies = TRUE)"); //rEngine.Evaluate("install.packages(\"jsonlite\",dependencies = TRUE)"); //rEngine.Evaluate("install.packages('httr')"); //rEngine.Dispose(); rEngine.Evaluate("library(forecast)"); //rEngine.Evaluate("install.packages(\"jsonlite\")"); rEngine.Evaluate("library(jsonlite)"); rEngine.Evaluate("library(tsoutliers)"); }
public MainWindow() { this.InitializeComponent(); int number = 2; foreach (var(x_, y_) in this.SelectData()) { this.Values.Add(x_, y_); } this.Values.KeyValueChanged += (a, b) => this.Act(number); this.DataGrid.ItemsSource = this.Values; this.PlotView.Model = new PlotModel(); this.engine = REngine.GetInstance(); Act(number); this.numberEvent += num => { number = num; var(x, y) = GetNumericVectors(); this.xBox.Text = string.Join(Environment.NewLine, SelectResult(x)); this.yBox.Text = string.Join(Environment.NewLine, SelectResult(y)); this.pBox.Text = string.Join(" ", engine.Evaluate("t.test(x,y)").AsList()); this.PlotPredictionAndData(number, x, y); }; }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".png"); Application.ThreadExit += (sender, e) => { try { File.Delete(path); } finally { } }; var form = new GraphForm() { Code = @"plot(1:10, pch=1:10, col=1:10, cex=seq(1, 2, length=10)) text(c(1), c(1), c('Text here'), col=c('red'))", TempImagePath = path, }; REngine.SetEnvironmentVariables(); var engine = REngine.GetInstance(); Application.ThreadExit += (sender, e) => engine.Dispose(); engine.Initialize(); engine.Install(form.graphPanel); Application.Run(form); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine(@"Usage:"); Console.WriteLine(@"SourceRCode.exe c:/path/to/source.r"); Console.WriteLine(@" (!) Do note that you should use forward slashes (simpler than backslashes here)"); return; } REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); engine.Evaluate("source('" + args[0] + "')"); /* * // Say your R file contains: * * sqr <- function(x) { * return(x*x) * } */ Console.WriteLine("By default, autoprint on the console"); double[] a = engine.Evaluate("sqr(0:5)").AsNumeric().ToArray(); Console.WriteLine("However, for manipulation of larger data, autoprint on the console is probably not a good idea"); engine.AutoPrint = false; a = engine.Evaluate("sqr(0:1000)").AsNumeric().ToArray(); Console.WriteLine("Length(a) is " + a.Length + ", but the vector has not been written out to the console"); Console.WriteLine("Press any key to exit the program"); Console.ReadKey(); engine.Dispose(); }
static void RMain(string[] args) { REngine.SetEnvironmentVariables(); // There are several options to initialize the engine, but by default the following suffice: using (REngine engine = REngine.GetInstance()) { // .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.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); // Test difference of mean and get the P-value. GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); double p = testResult["p.value"].AsNumeric().First(); Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); Console.WriteLine("P-value = {0:0.000}", p); // you should always dispose of the REngine properly. // After disposing of the engine, you cannot reinitialize nor reuse it // engine.Dispose(); } // End Using engine } // End Sub RMain
public void Rexecution() { //RScriptRunner rr = new RScriptRunner(); //string curDirectory = "D:\\VisualStudioCommunity\\DailyMonitoringCMC\\DailyMonitoringCMC\\App_Data"; //string result = RScriptRunner.RunFromCmd(curDirectory + @"\testCSharp.R", "rscript.exe",""); //@"C:\Program Files\R\R-3.2.3\bin\x64", @"C:\Program Files\R\R-3.2.3" //IMPORTANT: Engine.evaluate("source('\\\\\\\\something.x.y./somelocation/somefile.r');"); REngine.SetEnvironmentVariables(); // There are several options to initialize the engine, but by default the following suffice: REngine engine = REngine.GetInstance(); //engine.Evaluate("require('ggplot2')"); //engine.Evaluate("library('ggplot2')"); engine.Evaluate("print(plot.ts(c(1:100))"); //engine.Evaluate("source('D:\\Thesis R\\testCSharp.R')"); // .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.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); //// Test difference of mean and get the P-value. //GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); //double p = testResult["p.value"].AsNumeric().First(); //Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); //Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); // Console.WriteLine("P-value = {0:0.000}", p); // you should always dispose of the REngine properly. // After disposing of the engine, you cannot reinitialize nor reuse it engine.Dispose(); }
/// <summary> /// Run PCA in R engine /// </summary> static void PCAR() { const string directoryPath = @"C:\Users\Káťa\Desktop\Diplomka\mesh\meshes"; var matrix = loadFacesR(directoryPath); REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); NumericMatrix group1 = engine.CreateNumericMatrix(matrix); engine.SetSymbol("group1", group1); GenericVector testResult = engine.Evaluate("pr.out=prcomp(group1, scale=TRUE)").AsList(); var eigenVec = testResult["x"].AsNumericMatrix(); engine.Evaluate("pr.out$sdev"); engine.Evaluate("pr.var = pr.out$sdev ^ 2"); engine.Evaluate("pr.var"); engine.Evaluate("pve = pr.var / sum(pr.var)"); engine.Evaluate("pve"); engine.Evaluate("plot(cumsum(pve), xlab='Principal Component', ylab='Cumulative Proportion of Variance Explained', ylim=c(0,1),type='b')"); saveVector(eigenVec); // var eigenVec = testResult["pr.out&x"].AsNumericMatrix(); Console.ReadLine(); }
public RUtilService(IOppeDBService oppeDBService) { _oppeDBService = oppeDBService; REngine.SetEnvironmentVariables(); _engine = REngine.GetInstance(); _engine.Initialize(); }
static void Main(string[] args) { const string directoryPath = @"C:\Users\Káťa\Desktop\Diplomka\mesh\meshes"; var matrix = loadFacesR(directoryPath); REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); NumericMatrix group1 = engine.CreateNumericMatrix(matrix); //List<float>[] faceMatrix = new List<float>[] { }; //double[,] squere = new double[,] { { 13, -4, 2 }, // {-4 , 11 , -2}, {2 , -2 , 8 } }; //runR(squere); //int[] i = new int[] {}; // pokus(); // var matrix = getDataMatrix(directoryPath); // runR(); //REngine.SetEnvironmentVariables(); //REngine engine = REngine.GetInstance(); //// REngine requires explicit initialization. //// You can set some parameters. //engine.Initialize(); //NumericMatrix group1 = engine.CreateNumericMatrix(new double[,] { // { 0, 0, 0, 0, 1 }, // { 0, 0, 0, 1, 1 }, // { 0, 0, 1, 1, 1 }, // { 0, 0, 0, 1, 1 }, // { 0, 0, 0, 0, 1 } //}); //engine.SetSymbol("group1", group1); //GenericVector testResult = engine.Evaluate("eigen(group1)").AsList(); //Console.WriteLine("P-value = {0}", group1); // //.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.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); //// Test difference of mean and get the P-value. //GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); //double p = testResult["p.value"].AsNumeric().First(); //Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); //Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); //Console.WriteLine("P-value = {0:0.000}", p); //you should always dispose of the REngine properly. // After disposing of the engine, you cannot reinitialize nor reuse it // engine.Dispose(); Console.ReadLine(); }
public PeriodPredictor(string pathToDate) { SetupPath(); path = pathToDate; engine = REngine.GetInstance(); engine.Initialize(); }
static void Main(string[] args) { string result; string input; REngine engine; /* init the R engine */ REngine.SetEnvironmentVariables(); engine = REngine.GetInstance(); engine.Initialize(); /* input */ Console.WriteLine("Please enter the calculation"); input = Console.ReadLine(); /* calculate */ CharacterVector vector = engine.Evaluate(input).AsCharacter(); result = vector[0]; /* clean up */ engine.Dispose(); /* output */ Console.WriteLine(""); Console.WriteLine("Result: '{0}'", result); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }