From rukubites at gmail.com Sun Oct 7 10:02:27 2007 From: rukubites at gmail.com (Luke Hope) Date: Sun, 7 Oct 2007 20:02:27 +1000 Subject: [rclg-devel] FWD: RCLG In-Reply-To: References: <1abe3fa90710062359m2d910ce2jdf051a1c8d07a9af@mail.gmail.com> Message-ID: Ooops, wrong cc. ---------- Forwarded message ---------- From: Luke Hope Date: Oct 7, 2007 8:00 PM Subject: Re: RCLG To: "A.J. Rossini" Cc: rclg-devel at commonlisp.net Hi again, I spent the afternoon going through a basic R/stats tutorial. I'm not experienced with R, my background is machine learning and I want to get familiar with a real statistical language. For various reasons, I want to do it in lisp also, so here I am. Anyway, I have a request for help, a bugfix, a bug report, and a small enhancement. This might wake up the list. :) The request for help is: how do I express something like pairs ( iris[,1:4]) in rclg? It's not the 1:4 -> (r seq 1 4) that confuses me, it's the [,x] bit that has me lost. The bugfix is to support ratios (e.g. 2/9) input to R. The diff is at the bottom of the page. The bug: - Not specifying xlab causes the value of x to be displayed in plot/matplot instead of the default xlab "x" which occurs in R proper. E.G. (defparameter x (r seq 0 30)) (r plot x (rnbi dbinom x 30 .5) :ylab "p(x)") The enhancement makes e.g. [rfunc args] expand to (r rfunc args), unless you're already in an r block, which then expands to (rnbi rfun args). This REALLY improves readability, and makes something like: (setf x [rbinom 5000 100 .5]) (setf m [mean x]) (setf m1 [mean [^ [- x m] 3]]) A LOT less ugly (the third line in particular). (defparameter *in-r-block* nil) (defun enable-r-brackets (left right) (set-macro-character right (get-macro-character #\))) (set-macro-character left #'(lambda (stream char) (declare (ignore char)) `(,(if *in-r-block* 'rclg:rnbi 'rclg:r) ,@(let ((*in-r-block* t)) (read-delimited-list right stream t)))))) Cheers, -Luke Signed-off-by: Luke Hope --- src/rclg-convert.lisp | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/src/rclg-convert.lisp b/src/rclg-convert.lisp index 52daea2..808ff83 100644 --- a/src/rclg-convert.lisp +++ b/src/rclg-convert.lisp @@ -94,6 +94,7 @@ Assumes it's a string robj." (:method ((n null)) *r-nil-value*) (:method ((i integer)) (int-to-robj i)) (:method ((f float)) (float-to-robj f)) + (:method ((r ratio)) (ratio-to-robj r)) (:method ((d double-float)) (double-float-to-robj d)) (:method ((c complex)) (complex-to-robj c)) (:method ((s string)) (string-to-robj s)) @@ -124,6 +125,10 @@ Coerces the number to double-float since R has no sense of lower precision." (double-float-to-robj (coerce f 'double-float))) +(defun ratio-to-robj (r) + "Returns an R object corresponding to a CL ratio. +Coerces the number to double-float as a hack." + (double-float-to-robj (coerce r 'double-float))) (defun double-float-to-robj (d) "Returns an R object corresponding to a double floating point number." -- 1.5.3.2