Introduction

This tutorial will show you how to publish a service written in R . This language is provides a statistical environment and has many libraries which are not provided by Java. The process of publication of R is relatively similar to that for Java . This tutorial assumes that you have installed Java, Tomcat and Maven, as described in the requirements . If you have not tried the 10 minute introduction, you might like to start there. Although you need to write some Java, the level of knowledge required is very low; mostly for publishing R, you need to know R. The R code has been tested on both Unix and Windows and should run on both.

Generate a Skeleton

InstantSOAP uses the maven tool for building. In this case, we are going to use an "archetype" to generate the base structure. This is a matter of typing the following command.
mvn -e -B archetype:generate  -DarchetypeGroupId=uk.ac.ncl.cs.instantsoap \
  -DarchetypeArtifactId=archetype-r-tool -DarchetypeVersion="1.0-SNAPSHOT" \
  -DarchetypeRepository="http://metagenome.ncl.ac.uk/fluxions/repo-snapshot"  \
  -DgroupId=uk.ac.test -DartifactId=my_new_r_tool 
      
Depending on your operating system you may have to type this in on one line without the "\"'s. The last two lines should be replaced with something specific to your service.

Examining the code

The basic skeleton generates a service which produces the mean for a data frame in R.

Firstly find the file averageR.r . It should be in the directory my_new_r_tool/src/main/resources/uk/ac/test unless you have changed either the artifactId or the groupId in the last section . It should look like this:

process <-
  function (values)
  {
    return ( mean( values ) )
  }
      
The single function, process will be presented as a service. We'd suggest putting as little as possible in this file; calling out to your own function makes more sense, as you can test it independently of InstantSOAP. The function should expect a single data frame and return the same.

Secondly, you need a Java source file. Essentially, this is fairly dumb. It just provides metadata about the service. In this case, it's called RAverageProcessor.java . You can find this is the directory my_new_r_tool/src/main/java/uk/ac/test .

package uk.ac.test;

import org.bjv2.util.serviceprovider.SpiProvider;
import uk.ac.ncl.cs.instantsoap.r.RDataFrameProcessor;
import uk.ac.ncl.cs.instantsoap.wsapi.MetaData;
import static uk.ac.ncl.cs.instantsoap.wsapi.Wsapi.metaData;

/**
 * Calculates means for an input data frame
 *
 */
@SpiProvider
public class RAverageProcessor extends RDataFrameProcessor
{
    public String getRScriptName()
    {
        return "averageR.r";
    }
    

        
    // These are informational methods which are uncovered in the WSDL
    // interface of the service. 
    public MetaData describeApplication()
    { 
        return metaData( "average", "Calculates the mean for an R data frame" );
    }
    
    public MetaData getInput()
    {
        return metaData( "messageIn", "An R data frame to be averaged" );
    }
    
    public MetaData getOutputs()
    {
        return metaData( "output", "An R data frame with average values" );
    }

}
averageR.r is the name of the script in question. It needs to be in a location that mirrors that of the Java file (starting from src/resources and src/main respectively; so if you move RAverageProcessor.java into another package, averageR.r needs to be moved also. Other methods provide a description of the application, and information about the inputs and outputs respectively.

Compile and Deploy

From here, you should be able to follow the instruction for Java .