Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

Edited Unassigned: execute script [161]

$
0
0
I'm using VS2013 and R.net to execute some R script which is suppose to return matrix but it doesn't work.

here is the script :

m0 <- matrix(NA, 4, 0)
m2 <- cbind(1, 1:4)
colnames(m2) <- c('x','Y')
rownames(m2) <- rownames(m2, do.NULL = FALSE, prefix = 'Obs.')
m2

I would get this result if I ran it in R environment which is correct:
x Y
Obs.1 1 1
Obs.2 1 2
Obs.3 1 3
Obs.4 1 4

also if I execute it through R.net like below it works just fine and will return a NumericMatrix:

SymbolicExpression output = null;

engine.Evaluate("m0 <- matrix(NA, 4, 0)");
engine.Evaluate("m2 <- cbind(1, 1:4)");
engine.Evaluate("colnames(m2) <- c('x','Y')");
engine.Evaluate("rownames(m2) <- rownames(m2, do.NULL = FALSE, prefix = 'Obs.')");
output = engine.Evaluate("m2");

var matrix = output.AsNumericMatrix();

and matrix variable has contain a matrix ( 4 rows and 2 columns)

but when I saved it as script ( file name is SimpleMatrixWithNamedColumnsAndRows.R) and then I run it , it won't work , instead it just return a matrix with ( 1 row and 1 column)


engine.Evaluate("setwd('H:/FarzadDataCenter/Developing/R')");

var statement = string.Format(@"source('H:/FarzadDataCenter/Developing/R/LanguageLearning/SimpleMatrixWithNamedColumnsAndRows.R')");
var output = engine.Evaluate(statement);

var matrix = output.AsNumericMatrix();


but output is vector instead of matrix which has only two member which are:

Length = 2; RObjectType = List
[0]: RObjectType = Null
[1]: RObjectType = BuiltinFunction

anyone knows what is the problem ?




Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>