[R] Create variable by name

David Winsemius dwinsemius at comcast.net
Wed Oct 6 19:07:18 CEST 2010


On Oct 6, 2010, at 12:58 PM, David Winsemius wrote:

>
> On Oct 6, 2010, at 12:32 PM, Ralf B wrote:
>
>> Can one create a variable through a function by name
>
> Isn't that what "<-" does?
>
>>
>> createVariable <- function(name) {
>> 	outputVariable = name
>> 	name <- NULL
>> }
>>
>> after calling
>>
>> createVariable("myVar")
>
> ?assign   # and isn't this covered in R-FAQ?
> ?"<-"

Perhaps the fastest method would be to use back ticks:

 > cvn <- `<-`  # assign "assign" to a new name, "cvn"
 > cvn("n2", NULL)
 > n2
NULL

>
>
>>
>> I would like to have a variable myVar initialized with NULL in my
>> environment. Is this possible?
>>
>> Ralf
-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list