## YapR ##

YapR is a YAP module to enable the access to R-project facilities in the Prolog 
engine. The original work is from Joao Azevedo, and some ideas were taken from Nicos Angelopoulos R interface.

There are three main commands:

	r(Command)            : run a r command
	X <- Command          : if X is unbound, run a command and bind X to result
	RExp <- Command       : run RExp <- Command

Command is a Prolog term. The syntax of Command is as close to R as
possible, with some limitations. Major differences are:

   - replace X.Y by X..Y. Note that X must be an atom.
   - () is not accepted, but some functions are expanded automatically.
      data -> data()
   - use a^[2] for a[2]
   - a list of integers that are non-ascii control codes is a string
   - lists of lists of numbers, like [[1,2,3],[2,3,4]] are converted to 
matrices. All elements must have the same dimension.
   - filenames must be given as Prolog strings.
   - Prolog empty lists, [], are converted to "".
   - use ( f(x) :-  (..)) for f(x) (...)
   - use commands as atoms or strings, eg:

         label <- 'inp$id'

      if things get hairy.

Notice that some R operators, such as %*% must be quoted in Prolog.

Enjoy!

## Example Usage ##

    ?- use_module(library(yapr)).
    ?- X <- sum([1.0, 2.0, 3.0]).
    X = 6.0
    ?- x <- sort([3, 2.0, 3.0]).
    ?- X <- max(x).
    X = 3.0
    ?- X <- [[1,2,3],[4,5,6],[7,8,9]] '%*%' [[1,1],[1,1],[1,1]].
    X = [[12.0,12.0],[15.0,15.0],[18.0,18.0]]
    yes
    ?- X <- sqrt(16).
    X = 4.0
    ?- x <- [10,10], y <- 20, X <- x*y.
    X = [200.0,200.0]
    ?- X <- x^[1].
    X = 10.0
    ?- X <- paste("a","a",sep="").
    X = [97,97]
    ?- x<-c(10,10), y<-20, X<-as..integer(round(x*y,0)).
    X = [97,97]
    ?- r(source("tests/test.r")).
    yes

Examples from R tutorial

?- z <- 0:9.
yes
?- Z <- z.
Z = [0,1,2,3,4,5,6,7,8,9]
% notice the use of ..
?- digits <- as..character(z).
yes
?- Z <- digits.
Z = [[48],[49],[50],[51],[52],[53],[54],[55],[56],[57]]
?- d <- as..integer(digits).
yes
?- D <- d.
D = [0,1,2,3,4,5,6,7,8,9]

?- e <- numeric.
yes
?- e^[3] <- 17.
yes
?- Z <- e.
Z = ['$NaN','$NaN',17.0]
?- e^[10] <- 12.
yes
?- Z <- e.
Z = ['$NaN','$NaN',17.0,'$NaN','$NaN','$NaN','$NaN','$NaN','$NaN',12.0]
