TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
REngine.cs
Go to the documentation of this file.
1 // RPlugin - A framework for running R scripts in .NET
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using RPlugin.Exceptions;
18 using System.IO;
19 
20 namespace RPlugin.Core
21 {
25  public class REngine
26  {
27  private string _path;
28 
33  public REngine(string path)
34  {
35  if (!File.Exists(path))
36  {
37  throw new FileNotFoundException("Could not find part of the path to the RScript executable.", path);
38  }
39  _path = path;
40  }
41 
47  public object Execute(IRScript script)
48  {
50  script.PreCompute();
51  RScriptResult result = RController.RunScript(_path, script.BaseScript, script.Arguments);
52  if (result.ExitCode != 0)
53  {
54  throw new RExecutionException(script.BaseScript, script.Arguments, result.Output, result.Error);
55  }
56  return script.ImportResults(result);
57  }
58  }
59 }