I am trying to store the source code of a function within a list, but I want to pass the function name to the list as a string.
This works:
hello_world <- function() print("Hello World")
my_list <- list(func = hello_world)
my_list
# $func
# function ()
# print("Hello World")
But I want to be able to pass the function name as a string. This of course just gives me the string:
my_list <- list(func = paste("hello", "world", sep = "_"))
my_list
# $func
# [1] "hello_world"
I have tried:
my_list <- list(func = as.formula(paste("hello", "world", sep = "_")))
Error: object of type 'closure' is not subsettable
and:
my_list <- list(func = call(paste("hello", "world", sep = "_")))
my_list
# $func
# hello_world()
If anyone has any idea about how I can make this work, I would truly appreciate it.