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?
?"<-"
> "myVar" <- NULL
> myVar
NULL
Doing it a bit differently"
> "<-"("n1", NULL)
> n1
NULL
One could always wrap it in a function call.
> CVN <- function(name) { name <- NULL }
> CVN("test")
> test
NULL
If you needed a function that by default created the variable in the
global environment, then this would work:
> createGVarNULL <- function(name) {
+ assign(name, NULL, envir = .GlobalEnv) }
> createGVarNULL("test")
> test
NULL
An "assign" version of "<<-" I suppose.
"myVar" <- NULL
> myVar
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
______________________________________________
R-help@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.