Pregunta

I need some help on what may be a simple issue. I am trying to access R using a simple .Net /C# Console application.

I have installed the program R on a virtual Server which use Ubuntu 14.04 LTS as it's OS. I have also installed the package Rserve as well. With Rserve and a client library called RserveCLI, source code. I am now able to connect to the to the instance or R running on the virtual server.

Now here comes the problem, I can make the connection, but when i try to perform the example used in the source code with in my own solution. I am getting the following error:

"RserveCLI2.RserveException: Cannot decode an Sexp because the type is not recognized: 48"

            //Setting up the connection and sending information trhough connection to                 be processed
            using ( var s = new RConnection( new System.Net.IPAddress( new byte[] { 192 , 168 , 201 , 101 } ) , port: 6311 , user: NULL , password: NULL ) )
            {
                    // Generate some example data
                    var x = Enumerable.Range( 1 , 20 ).ToArray();
                    var y = ( from a in x select ( 0.5 * a * a ) + 2 ).ToArray();

                    // Build an R data frame
                    var d = Sexp.MakeDataFrame();
                    d[ "x" ] = Sexp.Make( x );
                    d[ "y" ] = Sexp.Make( y );
                    s[ "d" ] = d;

                    // Run a linear regression, obtain the summary, and print the result
                    var linearModelSummary = s[ "summary(lm(y ~ x, d))" ];
                    Console.WriteLine( linearModelSummary.Count );
            }

The error comes from it tries to process: var linearModelSummary = s[ "summary(lm(y ~ x, d))" ];

The issue is with the variable d. When I look at the serve with current instance I have opened with Rserve. It says "Error: object 'd' not found"

Tools And Software Used:

Visual Studio 2013,.Net Framework 4.5, R, Rserve Version=1.7-3, RServeCLI, Virtual Box Version = 4.3.10, OS on Laptop = Win 7 64 Bit, OS on Virtual Server = Ubuntu Server LTS 14.04

Any advice would be helpful as I am not sure what I am doing wrong. If you need any more information, please ask I will try and get it for you.

Thanks

¿Fue útil?

Solución

Do not try to use RServeCLI in that way, you will never get it to work reliably. Instead, put all code into a function in R, test it separately, and only pass values and data frames between R and c#.

In your case the problem is in the summary line, because this structure cannot be marshalled with the available tools. Transfer the results to a simple list or better, as a starter, to atomic variables.

Otros consejos

Thanks Dieter for the advice. Tried using the built in function getwd(), and performing basic arithmetic stuff. All working fine so far. Cheers

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top