Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Using EPL Plug-ins | Using the R plug-in | Steps for using the R plug-in
 
Steps for using the R plug-in
The events within the R Support bundle are in the com.apama.r package. It is assumed that R has been installed with Rserve and that it is running on a known host and port (see Introduction to using the R plug-in for more information).
After you have added the R Support bundle, you write EPL that does the following:
1. Create an RConnection event using the static open() or openDefault() action in the RFactory event with the known host and port. On Linux, the connection can be made using local sockets if the port is set to -1 and if the host is set to the socket filename.
2. Use the set() action in RConnection to set named variables in R. The set() action uses the any type, which means that all types can be passed into it.
Supported types are integer, float, string, boolean and sequence, including nested sequences or sequences of different types using any.
decimal and dictionary types are not supported. All unsupported types will cause an exception to be thrown.
3. Use the evaluate() action to evaluate an R expression and return the result. This action returns an any type and the user must process the result to the correct type.
Or use the evaluateAstype() action to evaluate an R expression, casting the result to the requested type. If the type is not correct, an exception will be thrown.
4. Close the connection using close().
See the API Reference for EPL (ApamaDoc) for more information on these actions.
open() can be called from different contexts. However, a matching host/port to an open connection will share the same connection.
Within R, everything is an array and R does not differentiate between a single value or an array which holds a single value. Because of this, the Apama R plug-in converts an array of a single value into a single value of the correct type. Therefore, if you set a sequence<integer> variable to [123], it will just be an integer of 123 when you retrieve this value.
Calls to the R plug-in are synchronous and block execution in the current context. You can create an asynchronous service in a dedicated context; a sample is provided to demonstrate this. See also R plug-in samples.