I'm trying to put something on CRAN that allows the user to manipulate reactive shiny objects by making an analogous static object on the search path. I know I cannot write to the global environment (what it currently does) but I'm not sure how to let the objects persist once the function is executed.
store_it <- function() {
env <- new.env()
assign("x", runif(10), env)
assign("iris_df", head(iris), env)
# View(env)
env
}
# how I want to use it, doesn't work
store_it() # <environment: 0x0000012bd8959cb0>
x # Error: object 'x' not found
iris_df # Error: object 'iris_df' not found
# works
e <- attach(store_it())
x
iris_df
It does what I want but I don't like that it keeps adding environments to the search path:
e <- attach(store_it())
# The following objects are masked from store_it() (pos = 3):
# iris_df, x
e <- attach(store_it())
# The following objects are masked from store_it() (pos = 4):
# iris_df, x
e <- attach(store_it())
# The following objects are masked from store_it() (pos = 5):
# iris_df, x
What's the right way to do this? I'd like the user to just write store_it()
. If attach()
is the right way, how do I put it in the function so it doesn't keep making new environments? Please keep in mind the solution needs to pass CRAN's policies. Thanks in advance.
Note: Someone will likely point out that I asked a similar question in the past. I made a new post because this question is more specific. Package environment manipulation and submitting to CRAN