RE: [R] How to extract function arguments literally

From: <Bill.Venables_at_csiro.au>
Date: Sat 30 Apr 2005 - 14:09:52 EST


instead of as.character(substitute(arg)) use deparse(substitute(arg))

: -----Original Message-----
: From: r-help-bounces@stat.math.ethz.ch
: [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Shigeru Mase
: Sent: Saturday, 30 April 2005 1:24 PM
: To: r-help@stat.math.ethz.ch
: Subject: [R] How to extract function arguments literally
:
:
: 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:
:
: lc=function(cmd){
: cmd=as.character(substitute(cmd))
: .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
:



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 14:13:53 2005

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