Re: [R] Obtaining argument name within a function

From: John Sorkin <jsorkin_at_grecc.umaryland.edu>
Date: Tue 19 Jul 2005 - 14:12:23 EST


Francisco,
I had exactly the same question a few days ago. Try the following:  

z<-function(x)
{
xName <- deparse(substitute(x))
cat(xName)
cat("The parameter name was ",xName,"\n")

}  

Let me know if this works.
n.b. the \n in the cat function is a signal to print the next piece of data
on the next line.  

John  

John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC and
University of Maryland School of Medicine Claude Pepper OAIC  

University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524  

410-605-7119
- NOTE NEW EMAIL ADDRESS:
jsorkin@grecc.umaryland.edu

>>> "Francisco J. Zagmutt" <gerifalte28@hotmail.com> 7/18/2005 10:16:53
PM >>>

Dear all

How can I obtain the name of the argument passed in a function? Here is a
simplistic example of what I would like to obtain:

myfunction= function(name) {

     print(paste("The parameter name was",unknownFunction(name))
     }

myfunction(myobject)
[1] "The parameter name was myobject"

Thanks

Francisco



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

        [[alternative HTML version deleted]]



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 Tue Jul 19 14:18:06 2005

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