Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created March 3, 2015 23:26
Show Gist options
  • Save felixlindemann/1af5ba8619b56594ab83 to your computer and use it in GitHub Desktop.
Save felixlindemann/1af5ba8619b56594ab83 to your computer and use it in GitHub Desktop.
Evalute Line and Fire Event including the Feedback of R
private SymbolicExpression EvaluateLine(String cmd)
{
String result = "";
// getTempfile name for sink
FileInfo f = new FileInfo(Path.GetTempFileName());
SymbolicExpression s = null;
try
{
// Activate sink
this.rEngine.Evaluate(string.Format("sink(\"{0}\")", f.FullName.Replace("\\", "/")));
// Evaluate Command and add Result to result list.
s = rEngine.Evaluate(cmd);
}
catch (Exception ex)
{
throw ex;
}
finally
{
// End sink
this.rEngine.Evaluate("sink()");
// read sink-Output from tempfile
result = File.ReadAllText(f.FullName);
// delete tempfile
this.rEngine.Evaluate(string.Format("unlink(\"{0}\")", f.FullName.Replace("\\", "/")));
// fire Event
CommandExecuted(new RExececutedEventArgs(cmd, result, s));
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment