Did you know ... Search Documentation:
Pack rserve_client -- prolog/r/r_term.pl
PublicShow source

This module deals with representing an R expression as a Prolog term. The non-terminal r_expression//2 translates the Prolog term into a string that can be sent to R.

The design is inspired by real from Nicos Angelopoulos.

 r_expression(+Term, -Assignments)//
Grammar that creates an R command from a Prolog term. Terms recognised:
  • The atoms true and false are mapped to TRUE and FALSE.
  • Other Prolog atoms are mapped to an R name. If required, the name is quoted using backquotes.
  • A term +(Atom) is mapped to an R string.
  • A Prolog string is mapped to an R string. The server should run in UTF-8 mode for exchange of Unicode data.
  • A Prolog number is mapped to an R number.
  • A Prolog list is added to Assignments. These are used to create a temporary R variable. The R command translation contains the variable name
  • Left$Right is translated as is.
  • An array index X[I,...] is translated as is. Empty elements in the index, e.g., the R expression a[,3] can be written as `a['',3], a[-,3] or a[*,3]`.
  • Known operators are passed as infix operators. The following operators are known: +, -, *, /, mod, '%%', ^, >=, >, ==, <, <=, =<, \=, '!=', :, <-
  • Expr1,Expr2 is translated into two R statements separated by a newline.
  • Compound terms are translated to function calls.

This library loads r_expand_dot.pl, which uses the `.` infix operator to make a.b and a.b() valid syntax.

Arguments:
Assignments- is a list Name=Value for data assignments.