import org.bioconductor.packages.rGlobalEnv.RChar;
import org.bioconductor.packages.rGlobalEnv.RGlobalEnvFunctionWeb;
import org.bioconductor.packages.rGlobalEnv.RGlobalEnvFunctionWebServiceLocator;
import org.bioconductor.packages.rGlobalEnv.RNamedArgument;
import org.bioconductor.packages.rGlobalEnv.RObjectName;
public class MainWS {
public static void main(String[] args) throws Exception{
RGlobalEnvFunctionWeb web=new RGlobalEnvFunctionWebServiceLocator().getrGlobalEnvFunctionWebPort();
String session=null;
try {
// via R-SOAP, obtain a session referencing an R Server by creating a new one or by connecting to an existing
// named R server if a non empty privatename is provided
session=web.logOn("", "login","pwd",new String[]{"privatename=titi"});
// submit to the R Server console via R-SOAP
web.consoleSubmit(session, "rstr<-'BBBBB'");
// arguments for the R 'paste' function
String arg1 = "AAA"; // Plain java string automatically converted to RChar
RObjectName arg2 = new RObjectName();arg2.setRObjectEnvironment("");arg2.setRObjectName("rstr"); // an R object Name referencing the R object 'rstr'
RChar arg3 = new RChar(); arg3.setValue(new String[]{"CCCC"}); // an RChar, java wrapper for R characters
RNamedArgument arg4 = new RNamedArgument(null, "sep","--"); // a named argument object holding an argument name ('sep') and an argument value (java string "--" automatically converted to RChar
String pasteResult=(String)web.callAndConvert(session, "paste", new Object[]{ arg1,arg2, arg3,arg4 }); // call the R function paste via R-SOAP and convert the result (an RChar) to a java plain String
System.out.println("paste result:"+pasteResult);
} finally {
// destroys the session, kills the R Server if an empty privatename has been provided on logon
web.logOff(session);
}
}
}
|