[R] printing the name of the arguments passed to a function
Spencer Graves
spencer.graves at pdf.com
Sun Jul 17 05:01:31 CEST 2005
How about the following:
> tstFn <- function(x){
+ xName <- deparse(substitute(x))
+ cat(xName)
+ "done"
+ }
> tstFn(Varname)
Varname[1] "done"
>
> tstF1 <- function(x){
+ tstF2 <- function(y){
+ cat(deparse(substitute(y)),
+ "doesn't work\n")
+ }
+ tstF2(x)
+ xName <- deparse(substitute(x))
+ tstF3 <- function(y, yName){
+ cat(yName, "works\n")
+ }
+ tstF3(x, xName)
+ "done"
+ }
> tstF1(Varname)
x doesn't work
Varname works
[1] "done"
spencer graves
John Sorkin wrote:
> R2.1.1
> Win 2k
> I have a function, B, within a function, A.
> I would like to have B print the name of the argument passed to it (not
> the value of the arguments).
> i.e.,
>
> A<-function()
> {
> B<-function(x,y)
> {
> fit1<-lm(y~x,data=jo)
> print(summary(fit1)
> I want B to print the string "age" and the string "height".
> }
> B(age,height)
> }
>
> I would like have function B print the name of the arguments passed to
> it, i.e. I want B to print the word
> age
> and the word
> height
>
> I would appreciate any suggestions that would help me accomplish this
> task.
>
> Thanks,
> 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 at grecc.umaryland.edu
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list