New in OpenCPU 1.4.4: session namespaces

August 25, 2014

The OpenCPU system exposes an HTTP API for embedded scientific computing with R. This provides reliable and scalable foundations for integrating R based analysis and visualization modules into pipelines, web applications or big data infrastructures.

This week version 1.4.4 was released on Launchpad (Ubuntu), and OBS (Fedora, SUSE) and CRAN.

New: session namespaces

A new feature in this version is support for session namespaces. Clients can now refer to objects within a temporary session using sessionid::name. This makes it easier to reuse objects that were created from a script. For example let’s execute the ch01.R script which is included with the MASS package:

>> curl -X POST

The x05af9fe89a is the temporary session ID, which will be different for every execution. From the output we can see that this script stored 7 objects in the session namespace. To retrieve the z object in json format, use:

But what if we want to reuse z the object in a subsequent function call? We can now do this using the sesssion namespace. For example, to calculate stats::sd(x = z), we need to refer to x05af9fe89a::z as shown below:

curl -d x=x05af9fe89a::z

This way, we can chain script executions and function calls by passing output objects as arguments to subsequent requests.

Function calls

For remote function calls, you can still use the session id alone to refer to the return object of the function call. For example to calculate stats::rnorm(n = 5) we do:

>> curl -d n=5

To calculate the standard deviation of our newly created object, the client can either use x009f9e7630::.val or simply x009f9e7630:

curl -d x=x009f9e7630
curl -d x=x009f9e7630::.val

The above two requests are equivalent.