[R] Function argument as string

Vishwanath Sindagi vishur6 at gmail.com
Thu Jun 17 06:39:18 CEST 2010


Perfect. Thanks Erik.

On Thu, Jun 17, 2010 at 1:07 AM, Erik Iverson <eriki at ccbr.umn.edu> wrote:
>
>
> Vishwanath Sindagi wrote:
>>
>> Hi,
>>
>> Suppose a write a function
>>
>> a_fn<-function(arg1)
>> {
>>
>>    return(table(arg1));
>> }
>>
>> I have a column called AGE. Now I call the function c = a_fn(AGE);
>>
>> When a_fn is called, AGE is received in arg1. My question is, how do I
>> access  the actual name of the argument arg1? i.e, inside the
>> function, i need to know that the actual name of arg1 is "AGE" in this
>> case.
>
> Is this what you mean ?
>
> fun <- function(x) {
>  as.character(substitute(x))
> }
>
>> fun(age)
> [1] "age"
>



More information about the R-help mailing list