search for: get_data_function

Displaying 1 result from an estimated 1 matches for "get_data_function".

2007 Apr 04
2
unexpected behavior when creating a list of functions
I wanted to create a list of functions whose output differs depending the value of a variable when the function was created. Generally this did not work. Each function was exactly the same, as in the simple example below: get_data_function <- function(v) { function() { print(v) } } data_functions <- sapply(1:10,function(v) get_data_function(v)) (data_functions[[1]])() # prints 10! However, if I insert a statement in get_data_function to print argument v, then I get the different functions that I wanted: get_data_funct...