Search code examples
rfunctionenvironment

Store function in a new environment, show function details


I am investigating if I can store all "user-defined-functions" in one environment, (not global environment). I manage to create the environment and send in the function inside the environment. I can also call for the function by refering to [environment$function].

However, I cannot fetch the details of the function.

Question: How can I view the details of the function that is located inside the environment?

My code:

# Create environment.
env_functions <- new.env() 

# Create function, send in to above mentioned environment.
env_functions$my_print <- function() {
print("hello")
}

Expected that this command should show details of the function:

ls.str(env_functions)

Results in:

my_print : function () # Why are the details of the function not visible?

The functions is however possible to be called:

env_functions$my_print()

Results in:

[1] "hello"

Solution

  • There is no reason why you can't use the standard way of just entering the function name, if you want to see the definition of the function:

    env_functions$my_print
    
    function () 
    {
        print("hello")
    }