[R] Calling LISP programs in R

From: francogrex <francogrex_at_mail.com>
Date: Wed, 23 Jul 2008 07:06:37 -0700 (PDT)

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)";
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.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 23 Jul 2008 - 17:11:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Jul 2008 - 20:34:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive