Hi,
while open the connection from C# to R (Statistical tool).Shows Error
System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {18C8B662-81A2-11D3-9254-00E09812F727} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Pls Help
Kezia
kezia johnpaulPosted Aug 22, 2014, 2:22 AM
Thanks for the reply,
I got the connectivity to R from c#.net,But can't set the Ilist variable to R
the Code I used:
[Test]
public void CTimeseries([Values(2014)]int year, [Values(8)]int month, [Values(1)]int day)
{
Connect();
IList
IList
var time = new DateTime(2013, 1, 1);
for (int i = 0; i < 10; i++)
{
facts.Add(new Fact(time, 10m * time.Month));
time = time.AddMonths(1);
};
int j = 0;
foreach (Fact f in facts)
{
Rarray.Add(f.TimeFrom.ToShortDateString());
Console.WriteLine("fact:{0}", f.TimeFrom);
j++;
}
foreach (var f in Rarray)
{
Console.WriteLine("Rarray:{0}", f);
}
rinterface.SetSymbol("tsName", Rarray);
rinterface.Evaluate("myts <- ts(mydata, start=c(2009, 1), end=c(2014, 12), frequency=12)");
var r_object = rinterface.GetSymbol("myts");
foreach (var f in r_object)
{
Console.WriteLine("myts:{0}", f);
}
rinterface.EvaluateNoReturn("library(forecast)");
rinterface.Evaluate(@"fit <- ets(myts,model=""ZZZ"")");
rinterface.Evaluate("plot(forecast(fit, 10))");
}
pls resolve the problem.why it is not working? Error shows in the line rinterface.SetSymbol("tsName", Rarray);
Thanks,
Kezia
Dipankar BiswasPosted Aug 18, 2014, 5:12 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
//COM references
using STATCONNECTORCLNTLib;
using StatConnectorCommonLib;
using STATCONNECTORSRVLib;
using System.IO;
namespace RConnector.Tests.Integration
{
[TestFixture]
public class TestConnectivityWithR
{
[Test]
public void Open_Close()
{
StatConnectorClass RConnector = new StatConnectorClass();
RConnector.Init("R");
RConnector.Close();
}
[Test]
public void Send_Receive_Data_()
{
StatConnectorClass RConnector = new StatConnectorClass();
RConnector.Init("R");
// Data we are going to pass
int n = 20;
// Cast C# type to R type
RConnector.SetSymbol("n1?, n);
// The cast value n to n1 is now being used in R
RConnector.Evaluate("x1 <- rnorm(n1)");
// We get back the value of x1, but it needs to be cast
// to an array of doubles
object o = RConnector.GetSymbol("x1?);
double[] random = (double[])o;
foreach (double d in random)
{
Console.WriteLine(d);
}
}
[Test]
public void Plot_CSharpInput_Simple()
{
StatConnectorClass RConnector = new StatConnectorClass();
RConnector.Init("R");
double[] input = new double[] { 1.0, 2.0, 3.0, 2.0, 1.0};
RConnector.SetSymbol("input", input);
RConnector.EvaluateNoReturn("hist(input)");
RConnector.EvaluateNoReturn(
"savePlot(filename = \"" +
@"C:\\Users\\Joachim\\Documents\\Debug\\Plot_CSharpInput.eps" + "\", " +
"type = \"eps\", device = dev.cur(), restoreConsole = TRUE )"
);
//RConnector.Close();
}
[Test] public void Plot_CSharpInput_Simple_WithColors_Rainbow()
{
StatConnectorClass RConnector = new StatConnectorClass();
RConnector.Init("R");
double[] input = new double[] {1.0, 2.0, 3.0, 2.0, 1.0};
RConnector.SetSymbol("input", input);
RConnector.EvaluateNoReturn("barplot(input, main=\"Foobar\", xlab=\"Value\", ylab=\"Frequency\", col=rainbow(7))");
RConnector.EvaluateNoReturn("legend(\"topleft\", c(\"Hello\", \"World\"), cex=0.6, bty=\"n\", fill=rainbow(5))");
RConnector.EvaluateNoReturn(
"savePlot(filename = \"" +
@"C:\\Users\\Joachim\\Documents\\Debug\\Plot_CSharpInput.eps" + "\", " +
"type = \"eps\", device = dev.cur(), restoreConsole = TRUE )");
//RConnector.Close();
}
}
}