This module make R available to SWISH using the Rserve R package. The module r_serve.pl implements a SWI-Prolog wrapper around the Rserve C++ client to realise the communication with the R server.
The Prolog view at R is inspired by real from Nicos Angelopoulos.
It consists of the following two predicates:
In addition, the quasi quotation r
is defined. The quasi quotation
takes Prolog variables as arguments and an R expression as content.
Arguments (Prolog variable names) that match R identifiers cause the
temporary of an R variable with that name bound to the translated Prolog
value. R quasi quotations can be used as isolated goals, as well as as
right-hand arguments to <-/2 and <-/1. The example below calls the R
plot()
function on the given Prolog list.
?- numlist(1,10,Data), {|r(Data)||plot(Data)|}.
Images created by the R session are transferred as SVG and sent to the SWISH console using pengine_output/1.
capture.output
.plot(width=3)
. The predicate also
supports multiple output destinations. Options processed:
false
(default true
), do not call the result.stdout
and Term
is a list of strings, each representing a line of output. The
list can be empty. If the hook fails, maplist(writeln, Term)
is
called to write the output to current_output
.size(Rows,Cols)
to deal with e.g., SWISH.r_execute(Assignments, Command, Result)
rserve:socket
is defined and not empty, it is taken
as the path to a Unix domain socket to connect to.rserve:port
and rserve:host
is defined, we
connect to the indicated host and port.After the connection is established, the session can be configured using the hook r_init_session/1. The default calls r_setup_graphics/2 to setup graphics output to send SVG files.
Format = svg
.R
. If
there is no connection, there are no images.dev.off()
.Rimage_base
and <ext> in
Rimage_ext
.