[R] How to extract function arguments literally

From: Shigeru Mase <mase_at_is.titech.ac.jp>
Date: Sat 30 Apr 2005 - 13:24:09 EST

Dear all,

One of my friends asked me if it is possible to extract actual R function arguments literally (precisely, as strings). The reason is simple. He feels sometimes awkward to attach quotation marks :-). What he actually wants is to pass R command arguments to XLisp subroutines (He has been an enthusiastic XLisp user for a long time and still tends to use R as a wrapper to XLisp). Is it possible, or should I advise him not to be so lazy? The following is his simple example to explain the situation.

R function "lc" which passes its argument to an Xlisp function:


    .XLisp("lcommand", cmd)}

Corresponding XLisp function "lcommand":

 (defun lcommand (str) (eval (with-input-from-string (s str) (read s))))

If the argument cmd is a string (i.e. with quotation marks) or has no space, it works fine.

> as.character(substitute(abc))

[1] "abc"

But, if it has no quotation marks or contains spaces, it yileds an error.

> as.character(substitute((def x1 x2))

Error: syntax error

He wants to use the syntax like lc((def x1 x2)), not like lc("(def x1 x2)").

Thanks in advance.

Shigeru MASE <mase@is.titech.ac.jp>
        Tokyo Institute of Technology
        Dept. of Math. and Comp. Sciences
        O-Okayama 2-12-1-W8-28, Tokyo, 152-8550, Japan

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Apr 30 13:28:57 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:31 EST