Hi Thomas & fellow R(D)Com users, 

Thanks for the excellent suggestion of using RserverManager. This would seem to 
be exactly what I need!
I have managed to get an example in VBA working (See VBA code at bottom of 
email). 

However, when I try to run a corresponding example using .NET with C# I run 
into difficulty. 
I can add a IStatConnector-objects to RserverManager with no problems but I 
can't seem to retrieve it back again!
In VBA the  RServerManager has a method called "Item" which I can pass in a 
string to retrieve my IStatConnector session!
The methods, classes, constructors for the  .NET example are quite different. 

Here is the C# code I used to set up an R session and store the IStatConnector 
called "RLink" into the RServermanager. 
Does anyone know how to get it back? i.e. can anyone translate the VBCode

Call RServerManager.ServerPool.Item("MyR").Server.EvaluateNoReturn("plot(x)")

to C#?


Regards

Wayne


'---------C# .NET example --------------
using StatConnectorCommonLib;
using STATCONNECTORSRVLib;
using RServerManager; 

 protected void Button1_Click(object sender, EventArgs e)
    {
        int n = 150; 
        StatConnector RLink = new StatConnector();
        RLink.Init("R");
        RLink.SetSymbol("n", n);
        Label1.Text = "here i go!"; 

        ServerPool mservermanager = new ServerPool();
        mservermanager.Add(RLink, "MyR");
    }

 protected void Button2_Click(object sender, EventArgs e)
    {
        Need a method to get "MyR" back!!!
    }


'------------- End C# Code -----------------

'---------VBA code example working correctly--------------
Sub RunRSession()
Call StartRSession
Call GetRSession
End Sub
'----------------------

'--------------------
Sub StartRSession()
Dim RLink As StatConnector
Dim mean As Double
Dim n As Long
Dim mservermanager As RServerManager.ServerPool

n = 150
Set RLink = New StatConnector
RLink.Init ("R")
RLink.SetSymbol "n", n
RLink.EvaluateNoReturn ("x <- 1:" & n)

Set mservermanager = New RServerManager.ServerPool

mservermanager.Add RLink, "MyR" 
'Add Rlink StatConnector Session to RServermanager amd call it MyR.
End Sub
'--------------------

'--------------------
Sub GetRSession()
' Recall StatConnector R session from RServerManager
Call RServerManager.ServerPool.Item("MyR").Server.EvaluateNoReturn("plot(x)")
End Sub

-------------------- End VBA Code --------------------------------------



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Thomas
Baier
Sent: 19 November 2008 09:55
To: R (D)COM and RExcel server related issues
Subject: Re: [Rcom-l] Building R(D)Com Web Application experiences


Dear Wayne,

[EMAIL PROTECTED] schrieb:
> One method of doing this is to define a static StatConnector class in C# 
> see for example:_ __<http://www.daniweb.com/forums/thread49952.html>_
> but I certainly don't think this would be a recommended approach!
> Alternatively I could store the instance of the StatConnectorClass to a 
> server side "Application Object" or "Session object"
> see for example:_ <http://www.csharphelp.com/archives/archive207.html>_ 
> (I have yet to test this approach).
> 
> Can anyone perhaps suggest another better approach?

I have not tried to use this in the context of a ASP.NET application, 
but I would suggest to have a look at RServerManager.

Using RServerManager, you can store IStatConnector-objects with a 
specific name in an object repository (RServerManager) and later 
retrieve the same objects by querying the object with its name.

Basic documentation and an adminstrative console is included in the 
R/Scilab (D)COM server setup.

Regards,
Thomas

_______________________________________________
Rcom-l mailing list
Rcom-l@mailman.csd.univie.ac.at
http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
More information (including a Wiki) at http://rcom.univie.ac.at


_______________________________________________
Rcom-l mailing list
Rcom-l@mailman.csd.univie.ac.at
http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
More information (including a Wiki) at http://rcom.univie.ac.at

Reply via email to