How to return result from Rscript after execute code in R.NET

Nov 20, 2015 at 6:49 AM
Edited Nov 20, 2015 at 6:51 AM
Dear Team
I have execute a script and which run without error and produce output, now I want to run same script in C# using R.NET it also execute properly but how to get result return from script ?

Please help !
here I am giving my script and C# code

My script
head(study123)
study123$lcmax<-log(study123$Cmax)
output<-aov(formula=lcmax~Treat,data=study123)
summary(output)
My C# code
            REngine.SetEnvironmentVariables();
            REngine engine = REngine.GetInstance();
            engine.Initialize();
            GenericVector testList = engine.Evaluate("source('D:/Rscript.r')").AsList();
            engine.Dispose();
How to fetch result from above code.
Here I got result from R
 Df Sum Sq Mean Sq F value  Pr(>F)   
Treat          1    3.7   3.732   8.747 0.00316 **
Residuals   1198  511.1   0.427                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Please help.
Nov 30, 2015 at 10:18 AM
You need to use same variable for summary.
Like this:
myResult <- summary(output);
Next step - you need to "parse" it. myResult is a list. Try to get values you need like you get myResult.
Developer
Dec 1, 2015 at 11:14 PM
A code sample to get started from is:
            var npkscript = @"
op <- options(contrasts = c('contr.helmert', 'contr.poly'))
npk.aov <- aov(yield ~ block + N*P*K, npk)
npk.sum <- summary(npk.aov)
            ";
            engine.Evaluate(npkscript);
            var m = engine.GetSymbol("npk.sum").AsList();
            var df = m [0].AsDataFrame();
            var names = df.Names;
            var colnames = df.ColumnNames;
            // should do some checkes on names

            double[] meanSqr = df["Mean Sq"].AsNumeric().ToArray();