-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutable state within a package #126
Comments
Note about using this approach in a package re: caching value. Context: I am calling an API and want to cache the list result. I am using an internal environment in the package, and tried the # Defining internal state value would be this way
the$active_version <- "2.10"
# Resetting the state to no active version would be mean setting to NULL or ""
the$active_version <- NULL # ""
# But caching value would require `env_cache`
get_cached_val <- function() { env_cache(the, "val", default) }
# Resetting / clearing the cache can't be done by setting to NULL
the$val <- NULL
# because cached value would still be return by `env_cache`.
# It requires `env_unbind()` probably
env_unbind(the, "val") For this type of usage, is this still interesting using Should "unset state" be a value with library(rlang)
the <- new_environment()
the$val
#> NULL
env_has(the, "val")
#> val
#> FALSE
the$val <- NULL
env_has(the, "val")
#> val
#> TRUE
the$val
#> NULL I am putting this here for thoughts - no expectation right now on an answer |
i.e.
the <- new.new(parent = emptyenv())
or similar.https://twitter.com/ID_AA_Carmack/status/575788622554628096 via @jimhester
The text was updated successfully, but these errors were encountered: