I would like to modify some code (or add / delete) in the environment where this code lives. I have found this topic really helpful: How to change on the fly a line of an existing function in R, but problem I have is that function I want to modify is not in the .GlobalEnv
and I don't know what is the name of this environment.
This environment I'm thinking about could be described as a B
environment from this answer on one of my previous question: What is an environment where exists all objects from all files sourced when running Shiny App?. So basically I would like to change some code in Shiny App. I managed to find the environment using environment()
function, but I see I can't replace the code.
Perhaps my problem can be shown using this code:
test <- function() 1
test()
#> [1] 1
environment(test)$test <- eval(parse(text = "function() 2"))
test()
#> [1] 1
.GlobalEnv$test <- eval(parse(text = "function() 3"))
test()
#> [1] 3
How can I make this line of code: environment(test)$test <- eval(parse(text = "function() 2"))
to work? i.e. how to change the object using environment()
?
@jpiversen let me kindly note you about this question.