WPS4R Tutorial

This quick tutorial will show you how to deploy a WPS process in WPS4R. Therefore we start with a one-line mini script and evolve it step-by-step till it is a whole integrated process.

In R, we call the runif- function to produce a single random number between to numbers, e. g. 0 and 1. This is basically what we want our process to do:

> runif(1, min=0, max=1)
[1] 0.6292043
  1. The first thing to do is to write an R script and consider input / output data of the process. Hence we specify the variables "min" and "max" for input and "output" for output.
    # random number:
    min = 0
    max = 1
    output = runif(1, min=min, max=max)

  2. Meta-information about input and output is required. Add an annotation for each one, which consists at least of a variable name (id-attribute) and its data type (type-attribute, see section supported input / output types). We also add default values (value-attribute) to the input annotations.
    Note that the declarations "min = 0" "max = 1" were replaced by annotations and therefore disappeared from the script so that it won't run in R as-is. This was recognized as a usability weakness. We consider correcting that by a different formalization.
    # wps.in: min, double, value = 0;
    # wps.in: max,double, value = 1;
    # random number:
    min = 0
    max = 1
    output = runif(1, min=min, max=max)
    # wps.out: output, double;

  3. In case you want to handle complex input or output, you need too read/write the data from within R and receive/pass the filename as input/output reference. To demonstrate this we generate a list of 100 random variables and pass it as a text file, using the write.table function in R.
    # wps.in: min, double, value = 0;
    # wps.in: max, double, value = 1;
    # wps.in: n, integer, value = 100;
    # random number:
    x = runif(n, min=min, max=max)
    output = "outputfilename"write.table(x, output)
    # wps.out: output, text;

  4. Add more metadata. A WPS process requires at least an id and can be described within the fields "title" and "abstract". Similar descriptions can be added for each input and output variable so that purpose and usage of the process is clear.
    # wps.des: id = R_andom, title = Random number generator, 
    # abstract = Generates random numbers for uniform distribution; 
    # wps.in: min, double, Minimum, All outcomes are larger than min, value = 0; 
    # wps.in: max, double, Maximum, All outcomes are smaller than max, value = 1;
    # wps.in: n, integer, ammount of random numbers, value = 100;  
    # random number: 
    x = runif(n, min=min, max=max)
    output = "outputfilename"
    write.table(x, output)
    # wps.out: output, text, Random number list, Textfile containing n random numbers in one column;

  5. Save the script file, e.g. as "WPS4R_andom.R", open your web browser; open the Web Admin Console of your WPS instance. You need the following access data:
  6. Upload the script. Therefore press the button "Upload R script" and fill out the upload form. You only got to specify the file location, but you also have the oportunity to give the process a (different) name, e.g. "R_andom". Submit the data. In the "algorithm repositories" tab, among the properties of the "LocalRAlgorithmRepository" should now occure one with value org.n52.wps.server.r.R_andom. This is the full process identifier, where the suffix org.n52.wps.server.r. denotes a namespace to distinguish WPS4R processes from others.

    Image: Upload script
    Figure 1: Upload the script

    Image: Repository
    Figure 2: Repository view - process ready to use

  7. Send WPS requests to test the process (change host/port if required):