Introduction to the Adapter for Rserve

Rserve is a TCP/IP server that allows users to run R scripts directly from WebFOCUS or the Reporting Server without the need to initialize R or link to an R library.

The adapter is available on UNIX, Linux, and Windows. On UNIX and Linux, Rserve allows parallel sessions and, therefore, the environment supports multiple users. On Windows, Rserve does not support parallel connections. Multiple sessions are shared, so the environment supports a single user at a time.

The installation of R and Rserve, and the creation of the model are done without server or WebFOCUS involvement, and are prerequisites for configuring and using the Adapter for Rserve.

Prerequisites

  1. Install R and Rserve on a host computer that has access to the WebFOCUS Reporting Server. Install them in a location for which you have write access.
  2. Create an R model that you will want to run from WebFOCUS.
  3. Save the R model (known as serialization) in a user script folder accessible to Rserve, using the R save command or the saveRDS function. The name and location of this folder will be determined by the Rserve administrator.
  4. Create a .csv file that has only those columns that will be used as independent variables in the model. Do not include the dependent variable.
  5. Write an R script to read and run the model.

R Script Features

The R script that will read and run the model must conform to the following rules:

For a complete example, see Sample Session: Creating a Synonym for an R Script and Running the Script.

Server and WebFOCUS Steps

Once you have a model and the R script that runs it, you need a sample .csv file that contains a few rows of data for the independent variables used in the model. This file will be used to determine the data types and lengths of the independent variables when you create a synonym for the model.

Later, when you run the model from WebFOCUS, you will need a data file to run against that will provide values for the input variables to be passed to the RSERVE function. The function will return the result of running the model as output.

Therefore, the following steps must be completed in the server Web Console and WebFOCUS.

  1. Configure the Adapter for Rserve, as described in Configuring the Adapter for Rserve.
  2. Upload the sample input file (.csv) to the server. This file is needed for creating the synonym for the model.
  3. Create a synonym for the model, as described in Creating a Synonym for an R Script.
  4. Make sure an adapter has been configured for access to the data source against which you want to run the model.
  5. Create a synonym for this data using the adapter configured in Step 4.
  6. From WebFOCUS, create a report or chart that uses the RSERVE function in a COMPUTE, passes it the input values (independent variables), and retrieves the result, as described in Sample Session: Creating a Synonym for an R Script and Running the Script.

The following diagram summarizes the process of preparing the model, named my_model, to be called in a WebFOCUS procedure.

The following diagram summarizes the process of calling the model named my_model in a WebFOCUS procedure (against a data source supported by R).

WebFOCUS

Feedback