Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "rserve_client"

Title:R Rserve client
Rating:Not rated. Create the first rating!
Latest version:1.1.0
SHA1 sum:eb438f8d3d2eb51b5d1ffa5e35b1fba167860ef0
Author:Jan Wielemaker <J.Wielemaker@cwi.nl>
Maintainer:Jan Wielemaker <J.Wielemaker@cwi.nl>
Packager:Jan Wielemaker <J.Wielemaker@cwi.nl>
Home page:https://github.com/JanWielemaker/rserve_client
Download URL:https://github.com/JanWielemaker/rserve_client/releases/V*.zip


No reviews. Create the first review!.

Details by download location


Rserve client for SWI-Prolog/SWISH

Rserve R-package:

Compiling this package

This library is configured as a SWI-Prolog pack. It can be installed using the command below. The installation requires git, autoconf and the common C++ build tools.

?- pack_install('rserve_client').

This is tested on Ubuntu (14.04 and 16.04). It performs these steps:

  • Clone my fork of Rserve (some extensions to the C++ client)
  • Configure and build the C++ client library
  • Build the SWI-Prolog interface rserve.so

Using this package

This package is primarily intended for accessing R in server environments such as SWISH. We created a Docker container that runs Rserve in a sandbox. The container exposes Rserve using a Unix-domain socket at the following address:


With SWISH and is interface installed in adjacent directories, i.e., below the same parent, R may be linked to SWISH doing

:- use_module(lib/r_swish).

Now, R is not safe. You should either run Rserve in a tight OS container and load library(r/r_sandbox) or run SWISH in authenticated mode by loading lib/authenticate.pl.

Libraries provided

User libraries

Defines basic user API to R
Utilities to create and fetch R data frames

Implementation libraries

Allow for dots in atoms and functors without quotes.
R Parser utilities (lexer) that support R quasi quotations
DCG non-terminal to translate a term into an R command string
Declare the R API sandbox-safe
Low-level level communication library


This is just a proof of context. Obviously missing functionality:

  • Cover more Prolog term --> R translations, following Real.
  • Support OOB (Out Of Band) communication introduced in recent versions of Rserve to deal with R I/O.

Related projects

This interface is inspired by Real by Nicos Angelopoulos. Main differences:

  • Real is embedded in SWI-Prolog. This is more productive for local deployment as the communication is faster and R has access to its default environment. Thus, R can open graphical windows and can read and write files. Real is also much more mature, notably in the supporting a much larger part of the R syntax from Prolog.
  • Rserve runs typically using a different user in a different environment. The R environment cannot easily communicate with your local development environment. When used in a (web) server environment this comes with several advantages. We can seriously sandbox the R executable, each query in SWISH gets its own R instance and information can thus nog leak between queries and users.

Contents of pack "rserve_client"

Pack contains 13 files holding a total of 73.9K bytes.