
r_call.pl -- R plugin for SWISHThis 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.
<-(Var, Expression) is det
<-(Expression) is detcapture.output.
r_call(+Fun, +Options)plot(width=3). The predicate also
supports multiple output destinations. Options processed:
false (default true), do not call the result.
r_console(+Stream, ?Term)[multifile]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.
r_execute(+Assignments, +Command, -Result) is det
r_unbind(+Bindings)[private]
r_setup_console(+R)[private]size(Rows,Cols) to deal with e.g., SWISH.
r(+Content, +Vars, +VarDict, -Goal) is detr_execute(Assignments, Command, Result)
diff_to_atom(+Start, +End, -Atom)[private]
rserve:r_open_hook(+Name, -R)[multifile]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.
r_setup_graphics(+Rconn, +Format) is detFormat = svg.
r_send_images is det[private]
r_display_images(+Images:list)[multifile]
r_images(-Images:list) is semidet[private]R. If
there is no connection, there are no images.dev.off().Rimage_base and <ext> in
Rimage_ext.