New in OpenCPU 1.4.4: session namespaces

[This article was first published on OpenCPU, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

opencpu logo

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.

To leave a comment for the author, please follow the link and comment on their blog: OpenCPU. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)