[R] Calling LISP programs in R

francogrex francogrex at mail.com
Wed Jul 23 16:06:37 CEST 2008


I have written some programs in Common Lisp and I have been using SAS to pipe
those programs to my lisp compiler in batch mode by using the %xlog and
%xlst SAS commands. I wonder if there is in R a similar way to pipe commands
to LISP so that all my work would be concentrated in R even when I have to
call a LISP program? I have looked at the foreign library but this seems to
adjust data types not for piping commands in batch mode. 

Here is a simple program (example) to generate random normal variables from
SAS to LISP; of course it's a toy example because there is no need for a
LISP routine in this particular case. I hope R has a similar feature. Thanks
DATA _NULL_;
FILE 'c:\cl.lisp' LRECL=1024;
PUT "(defun run (num Mn SD)";
PUT   "(setq mix  (list nil))";
PUT   "(dotimes (n num)";
PUT    "(setq u (- (* 2 (random 1.0)) 1)"; 
PUT    "v (- (* 2 (random 1.0)) 1)"; 
PUT    "w (+ (expt u 2) (expt v 2)))";
PUT    "(when (< w 1)";
PUT      "(progn";
PUT        "(setq z (sqrt (/ (* -2 (log w)) w))";
PUT        "x (* u z)";
PUT        "y (* v z)";
PUT         "mix (append (list x)  mix)";
PUT         "mix (append (list y)  mix)))))";
PUT   "(setq mix (remove nil mix)";
PUT   "mixnew (loop for x in mix append (list(+ Mn (* SD x)))))";
PUT   "(print mixnew)";
PUT   "(flet(( mean(zlist)";
PUT     "(setq sum (loop for x in zlist sum x))";
PUT     "(setq m (/ sum (length zlist)))))";
PUT   '(pprint (list "The mean is:" (mean mixnew))))';
PUT   "(flet((var(zlist)";
PUT     "(setq sumsq (loop for x in zlist sum (* (- x m) (- x m)))";
PUT     "v (/ sumsq (- (length zlist) 1)))))";
PUT   "(setq std (sqrt (var mixnew))))";
PUT   '(pprint (list "The Standard Deviation is:" std)))';
PUT "(run 500 41 17.5)";
RUN;
%xlog(CL);

-- 
View this message in context: http://www.nabble.com/Calling-LISP-programs-in-R-tp18611512p18611512.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list