[R] Create variable by name

Jeffrey Spies jspies at virginia.edu
Wed Oct 6 18:56:15 CEST 2010


An alternative to Peter's solution:

createVariable <- function(name) {assign(name, NULL, envir=.GlobalEnv)}

Jeff.

On Wed, Oct 6, 2010 at 12:32 PM, Ralf B <ralf.bierig at gmail.com> wrote:
> Can one create a variable through a function by name
>
> createVariable <- function(name) {
>        outputVariable = name
>        name <- NULL
> }
>
> after calling
>
> createVariable("myVar")
>
> I would like to have a variable myVar initialized with NULL in my
> environment. Is this possible?
>
> Ralf
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list