Have you reviewed the old
xlisp machinery that used to
be in R? Check out the RXLisp
library at
http://www.omegahat.org/RXLisp/
and see if this will work. The
PDF
http://www.omegahat.org/RXLisp/examples.pdf
reviews calling xlisp from R.
HTH
Steve McKinney
-----Original Message-----
From: r-help-bounces at r-project.org on behalf of francogrex
Sent: Wed 7/23/2008 7:06 AM
To: r-help at r-project.org
Subject: [R] Calling LISP programs in R
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.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.