I would like to use values within variables for defining functions in R. However, after declaring the function I can still see the variable names instead of their values inside the function definition. Here is an example:
> variable <- 10 > fn <- function() {message(variable*2)} > fn function() {message(variable*2)} And what I am expecting to see:
> variable <- 10 > fn <- function() {message(variable*2)} > fn function() {message(10*2)} How could I fix this?
variableto be a free variable, you can create a closure around it, but it won't change the function definition. Is this just a display issue? Or is there some behavior that you are trying to change?force(variable).