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:

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/

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:

Related projects

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

Prolog files

pack.plShow source
prolog/r/  -- R plugin for SWISHShow source
prolog/r/  -- R data frame handlingShow source
prolog/r/r_expand_dot.plShow source
prolog/r/  -- R parser primitivesShow source
prolog/r/  -- Declare the R API safeShow source
prolog/r/  -- SWI-Prolog Rserve clientShow source
prolog/r/  -- Translate a Prolog term into an R expressionShow source