2

How to use Rcaller to get more than one result in one time? For example,I use

code.addRCode("data<-read.table(\""+ "/home/yo/Documents/Book1.csv"+ "\", header=TRUE,sep=\"\t\")");
caller.setRCode(code);
caller.runAndReturnResult("data");

Then,I can use caller.getParser().getNames().size() ...e.g.function

But if I want to run summary(data$pH) ,how do I should do?Add to code before?If that the "caller"belongs to which? Thanks anyone who help me!

jbytecode
  • 681
  • 12
  • 29
Weiqi Wang
  • 29
  • 4

2 Answers2

1

you may find this here . it demostrate how we can get result from RCaller using runAndReturnValue method

http://stdioe.blogspot.com.tr/search/label/rcaller

marbel
  • 7,560
  • 6
  • 49
  • 68
Shashank gaur
  • 55
  • 1
  • 7
1

Use lists of results in R. For example you have a list of

result <- list(a=c(1,2,3), b=3.6, c=5) 

after calling rcaller.runAndReturnResult(result), the variables a, b and c are accessible wia

double[] a = rcaller.getParser().getAsDoubleArray("a");

or

int c = rcaller.getParser().getAsIntegerArray("c")[0];

With getNames() method, you can get the names contained in the 'result' list as well.

When you use summary(), nothing changes. Suppose you make a lm() call in R like

ols <- lm (y ~ x + z, data=mydata)

and then

detailed <- summary(ols)

and this is also a list, as the returned value of lm(). You can access elements of this list using

double[] residuals = rcaller.getParser().getAsDoubleArray("residuals");

and

double rsquared = rcaller.getParser().getAsDoubleArray("r.squared")[0];

Nothing changes after summary(). Back to your code

code.addRCode("data<-read.table(\""+ "/home/yo/Documents/Book1.csv"+ "\", header=TRUE,sep=\"\t\")");
caller.setRCode(code);
caller.runAndReturnResult("data");

does not return a list, you can type rather

RCode code = new RCode();
code.addRCode("myresult <- list(res1=data$pH, res2=data$anotherVector)");
rcaller.setRCode(code);
caller.runAndReturnResult("myresult");

After all,

double[] pH = caller.getParser().getAsDoubleArray(pH);

returns your pH variable.

For further information, visit the official blog here

jbytecode
  • 681
  • 12
  • 29