[R] generically setting attributes of a function

Liaw, Andy andy_liaw at merck.com
Wed Mar 9 00:49:10 CET 2005


If you can explain what you intend to do with that attribute, perhaps
someone might be able to help better.  Short of that, would the following
work for you?

> w <- structure(function(x) x^2, name="w")
> w
function(x) x^2
attr(,"name")
[1] "w"


Andy

> From: shang stud
> 
> Hello all:
> 
> I wonder if there is a generic way to assign the name of a 
> function as an
> attribute of the function. For example,
> 
> w = function(x) x^2;
> attr(w, "name") =  "w";
> 
> This assigns the name attribute of function w to be "w".
> 
> Would it be possible to put the second line of the code inside the
> function definition? I would like to avoid typing specifically the
> name, "w", when assigning the attribute.
> 
> Many thanks in advance.
> 
> Fang
> 
> ______________________________________________
> 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