SWI-Prolog/SWISH client for Rserve
This repository has been archived on 2021-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Franco Masotti 82b2328e07 Fixed typo and link. 2016-10-14 16:24:09 +02:00
Rserve@f6ab75a649 Updated Rserve 2016-08-05 14:05:53 +02:00
cc Removed some remaining copy/paste 2016-08-16 15:01:08 +02:00
prolog/r FIXED: Declare R quasi quotation safe. 2016-09-27 12:19:23 +02:00
.gitignore BUILD: Turn the Rserve interface into a pack. 2016-08-08 14:20:17 +02:00
.gitmodules Added Rserve as a submodule 2016-08-05 14:02:43 +02:00
LICENSE Added a license. Added important information in the readme. 2016-10-14 16:18:57 +02:00
Makefile Added a license. Added important information in the readme. 2016-10-14 16:18:57 +02:00
README.md Fixed typo and link. 2016-10-14 16:24:09 +02:00
pack.pl Added a license. Added important information in the readme. 2016-10-14 16:18:57 +02:00

README.md

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) and on Antergos GNU/Linux

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 in home/rserve/socket

Integration with SWISH

With SWISH and his interface installed in adjacent directories, i.e., below the same parent, R may be linked to SWISH by adding the following to run.pl:

:- use_module(lib/r_swish).
:- use_module(library(r/r_sandbox)).

Instead of using :- use_module(library(r/r_sandbox))., you can also run SWISH in authenticated mode by loading lib/authenticate.pl.

If you use the provided Docker image, don't forget to add SWISH's running user to rserve:

# gpasswd -a <SWISH's user> rserve

Final test

Finally you can test the installation by executing the following query as described here

?- <- 'R.Version'().

Libraries provided

User libraries

  • library(r/r_call) Defines basic user API to R
  • library(r/r_data) Utilities to create and fetch R data frames

Implementation libraries

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

Status

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.

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.

License

Copyright (c) 2016, Jan Wielemaker, Franco Masotti. 2-Clause BSD (aka FreeBSD).