本文整理匯總了C#中RDotNet.REngine類的典型用法代碼示例。如果您正苦於以下問題:C# REngine類的具體用法?C# REngine怎麽用?C# REngine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
REngine類屬於RDotNet命名空間,在下文中一共展示了REngine類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DoTest
private static void DoTest(REngine engine)
{
var setupStr = @"library(deldir)
set.seed(421)
x <- runif(20)
y <- runif(20)
z <- deldir(x,y)
w <- tile.list(z)
z <- deldir(x,y,rw=c(0,1,0,1))
w <- tile.list(z)
z <- deldir(x,y,rw=c(0,1,0,1),dpl=list(ndx=2,ndy=2))
w <- tile.list(z)
";
engine.Evaluate(setupStr);
var res = new List<List<Tuple<double, double>>>();
var n = engine.Evaluate("length(w)").AsInteger()[0];
for (int i = 1; i <= n; i++)
{
var x = engine.Evaluate("w[[" + i + "]]$x").AsNumeric().ToArray();
var y = engine.Evaluate("w[[" + i + "]]$y").AsNumeric().ToArray();
var t = x.Zip(y, (first, second) => Tuple.Create(first, second)).ToList();
res.Add(t);
}
}
示例2: TestPendingFinalizersThreadingIssues
private static void TestPendingFinalizersThreadingIssues(REngine e)
{
e.Evaluate("f <- function(a) {if (length(a)!= 1) stop('What goes on?')}");
var f = e.Evaluate("f").AsFunction();
try
{
e.Evaluate("f(letters[1:3])");
}
catch (EvaluationException)
{
}
f.Invoke(e.CreateCharacterVector(new[] { "blah" }));
try
{
f.Invoke(e.CreateCharacterVector(new[] { "blah", "blah" }));
}
catch (EvaluationException)
{
Console.WriteLine("Caught the expected exception");
}
f = null;
GC.Collect();
GC.WaitForPendingFinalizers();
e.Dispose();
Console.WriteLine("Just waiting for crash...");
GC.Collect();
GC.WaitForPendingFinalizers();
}
示例3: RService
public RService()
: base()
{
string RLogFilename = DirectoryHelper.GetLogFileName();
this._log = new RDotNetConsoleLogDevice();
this._log.LogDevice = new Journal() { FileName = RLogFilename };
logService.WriteToLogLevel("R DotNet Server (deepest function call) initialization started.", LogLevelEnum.Info);
try
{
StartupParameter sp = new StartupParameter();
REngine.SetEnvironmentVariables(null, null );//can set R Path and R Home by passing params
this._RServer = REngine.GetInstance();//null, true, null, _log);
this._RServer.Initialize();
logService.WriteToLogLevel("R DotNet Server initialized.", LogLevelEnum.Info); //writes to ApplicationLog
_log.WriteConsole("R.Net Initialized!!!", 1024, RDotNet.Internals.ConsoleOutputType.None); //writes to RLog
}
catch (Exception ex)
{
_log.WriteConsole("Unable to initialize R Server.(note: 64bit R must already be present)", 5, RDotNet.Internals.ConsoleOutputType.None);//Added by Anil
logService.WriteToLogLevel("Unable to initialize R Server.", LogLevelEnum.Error, ex);
throw new Exception();
}
logService.WriteToLogLevel("R DotNet Server (deepest function call) initialization ended.", LogLevelEnum.Info);
}
示例4: Form1
public Form1()
{
InitializeComponent();
string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
saveFileDialog1.InitialDirectory = "c:\\";
saveFileDialog1.FileName = "dimer_result.xlsx";
saveFileDialog1.Filter = "Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*";
configDoc.Load(strFileName);
progressBar1.Visible = false;
string installHome = Environment.GetEnvironmentVariable("PRIMERDIMERTOOL_HOME");
if (installHome != null)
{
installPath = installHome;
}
else
{
installPath = getConfigSetting("installpath");
}
Environment.SetEnvironmentVariable("PATH", installPath + "/Primer3/");
Environment.SetEnvironmentVariable("JAVA_HOME", installPath + "/Java");
REngine.SetEnvironmentVariables(installPath + "/R/bin/x64", installPath + "/R");
engine=REngine.GetInstance();
}
示例5: calcSDev
static double calcSDev (REngine engine, double[] arr)
{
// Note: only one quick and slightly dirty way to do it
NumericVector rVector = engine.CreateNumericVector(arr);
engine.SetSymbol ("x", rVector);
return engine.Evaluate ("sd(x)").AsNumeric () [0];
}
示例6: frmData
public frmData()
{
InitializeComponent();
// There are several options to initialize thengine, but by default the following suffice:
engine = REngine.GetInstance();
engine.Initialize();
}
示例7: ReproStackOverflow_34355201
private static void ReproStackOverflow_34355201(REngine engine)
{
engine.AutoPrint = true;
//samples taken from ?fscores man page in package mirt
engine.Evaluate("library(mirt)");
// 'Science' is a prepackage sample data in mirt; you can use 'engine.CreateDataFrame' in C# to create your own if need be.
engine.Evaluate("mod <- mirt(Science, 1)");
engine.Evaluate("class(mod)");
S4Object modcs = engine.GetSymbol("mod").AsS4();
// TODO - noticed 2015-12 that R.NET 1.6.5, HasSlot causes a stack imbalance warning. To unit test.
// Normally should do:
// if (modcs.HasSlot("Fit"))
IDictionary<string, string> slotTypes = modcs.GetSlotTypes();
if (slotTypes.Keys.Contains("Fit"))
{
GenericVector fit = modcs["Fit"].AsList();
// should check logLik in fit.Names;
double logLik = fit["logLik"].AsNumeric()[0];
}
engine.Evaluate("tabscores <- fscores(mod, full.scores = FALSE)");
engine.Evaluate("head(tabscores)");
engine.Evaluate("class(tabscores)");
NumericMatrix tabscorescs = engine.GetSymbol("tabscores").AsNumericMatrix();
}
示例8: rdotnet_discussions_646729
static void rdotnet_discussions_646729(REngine engine)
{
var setup = @"library(rdotnetsamples)
rdotnetsamples::register_default_progress_handler()
";
engine.Evaluate(setup);
var myRFunction = @"
my_r_calculation <- function()
{
for (i in seq(0, 100, by=20)) {
rdotnetsamples::broadcast_progress_update(paste0('Some Update Message for ', i), i);
}
}
";
engine.Evaluate(myRFunction);
engine.Evaluate("my_r_calculation()");
var unixDllPath = engine.Evaluate("getLoadedDLLs()$rdotnetsamples[['path']]").AsCharacter()[0];
var dllPath = unixDllPath.Replace("/", "\\");
var dll = new DynamicInterop.UnmanagedDll(dllPath);
TestCallback cback = new TestCallback();
CallBackHandlers cbh = new CallBackHandlers();
cback.MyHandler = cbh.ProcessProgress;
string cFunctionRegisterCallback = "register_progress_handler";
register_default_progress_handler registerHandlerFun = dll.GetFunction<register_default_progress_handler>(cFunctionRegisterCallback);
registerHandlerFun(cback.MyHandler);
Console.WriteLine();
Console.WriteLine("After registering the callback with a function pointer to a C# function:");
Console.WriteLine();
engine.Evaluate("my_r_calculation()");
}
示例9: RGraphForm
public RGraphForm()
{
InitializeComponent();
REngine.SetDllDirectory(GetRPath());
REngine.CreateInstance("RDotNet");
engine = REngine.GetInstanceFromID("RDotNet");
cbt = new RGraphAppHook {GraphControl = RPanel1};
}
示例10: CodeController
public CodeController()
{
if (_engine != null) return;
_engine = REngine.GetInstance(null, true, null, CharacterDevice);
_engine.Initialize();
_engine. .Install(GraphicsDevice);
}
示例11: RuntimeDiagnostics
public RuntimeDiagnostics(REngine engine)
{
this.engine = engine;
Types = new string[0];
Sizes = new int[0];
What = "";
Operation = "";
Tag = "";
}
示例12: stackoverflow_27689786_2752565
/// <summary>
/// http://stackoverflow.com/q/27689786/2752565
/// </summary>
static void stackoverflow_27689786_2752565 (REngine engine)
{
var rand = new System.Random (0);
double[] randValues;
for (int i = 0; i < 10; i++) {
randValues = mkValues (rand, 100);
Console.WriteLine ("std dev iteration {0} = {1}", i + 1, calcSDev (engine, randValues));
}
}
示例13: ReproIssue169
private static void ReproIssue169(REngine engine)
{
engine.Evaluate("library(mirt)");
engine.Evaluate("x=mirt(Science,1)");
S4Object obj111 = engine.GetSymbol("x").AsS4();
engine.Evaluate("ff=fscores(x, response.pattern=c(1,0,0,0))");
GenericVector dataset111 = engine.GetSymbol("ff").AsList();
NumericVector v = dataset111[0].AsNumeric();
double firstval = v[0];
}
示例14: ReproWorkitem45
public static bool ReproWorkitem45(REngine engine, int numThreads = 1)
{
for (int i = 0; i < numThreads; i++)
{
Graphics = new Thread(Repro45Thread);
Graphics.Start(engine);
}
//Started = true;
return true;
}
示例15: Form1
public Form1()
{
InitializeComponent();
this.FormClosed += new FormClosedEventHandler(OnFormClosed);
REngine.SetEnvironmentVariables();
engine = REngine.GetInstance();
// REngine requires explicit initialization.
// You can set some parameters.
engine.Initialize();
}