[R] Using Object's Name in Function

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Mon May 6 14:46:02 CEST 2002


> 
> 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"
> 
> It shall return "foo", "goo" (with or without quotes is fine), where foo
> and goo are two vectors with numbers.
> 

This should be a good place to start

> myfunc <- function(x,y) {
+   call <- match.call()
+   as.character(call)[-1]
+ }
> foo <- exp(1)
> myfunc(foo,"goo")
[1] "foo" "goo"
> 

Sundar

-- 

Sundar Dorai-Raj, Ph.D.
Statistical Methods Engineer
PDF Solutions, Inc.
Richardson TX
(972) 889-3085 x216
(214) 392-7619 cell
sundard at pdf.com
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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