How do I create a variable from function input? For example,
test <- function(var_name, num) {
var_name <<- 2 + num
}
test(hello, 2)
so hello will then be 4?
I think what you want is something like this:
test <- function(var_name, num) {
assign(var_name, num + 2, envir = .GlobalEnv)
}
test("hello", 2)
Here assign creates the varible var_name in the gobal environment (you need to set the envir parameter to .GlobalEnv to do that). Notice that the var_name parameter should be a string.
test(hello,2) you can use assign(deparse(substitute(var)), num+2, envir=.GlobalEnv) -- but please see @MrFlick's comment above.
hello <- test(2)