[R] Using Object's Name in Function

Jason Turner jasont at indigoindustrial.co.nz
Mon May 6 12:54:49 CEST 2002


On Mon, May 06, 2002 at 09:18:19PM +1200, Ko-Kang Kevin Wang wrote:
> Hi,
> 
> Suppose I have a function:
> myfunc <- function(x, y) {
>  ...
> }
> 
> And within the function I want to print out the name of the x, y
> vectors.  For example, if I do:
> > myfunc(foo, goo)
> [1] "foo" "goo"
> 

Something like 
myfunc <- function(x,y,...) {
	c(deparse(substitute(x)),deparse(substitute(y)))
}

myfunc("foo","goo")
[1] "\"foo\"" "\"goo\""

zz <- "foo"
zy <- "goo"
myfunc(zz,zy)
[1] "zz" "zy"
 
Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list