[R] How to extract function arguments literally
Bill.Venables@csiro.au
Bill.Venables at csiro.au
Sat Apr 30 06:09:52 CEST 2005
instead of as.character(substitute(arg)) use deparse(substitute(arg))
: -----Original Message-----
: From: r-help-bounces at stat.math.ethz.ch
: [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Shigeru Mase
: Sent: Saturday, 30 April 2005 1:24 PM
: To: r-help at 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 at 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 at 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
:
More information about the R-help
mailing list