We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Is it possible to have a function is_cached that checks if a call is already in the cache?
is_cached
Something like this (doesn't work, as I don't fully understand the internals of memoise()).
memoise()
is_cached <- function(f, ...) { stopifnot(is.memoised(f)) args <- list(...) cc <- environment(f)$`_cache` cc$has_key(cc$digest(c(body(f), args))) } myfun <- memoise(function(name = "Alice") print(paste("Hello", name))) myfun("Alice") is_cached(myfun, "Alice") # TRUE is_cached(myfun, name = "Alice") # TRUE is_cached(myfun, name = "Bob") # FALSE
Even better: if the is_cached function is able to take the call to the memoised function is_cached(myfun("Alice")).
is_cached(myfun("Alice"))
The text was updated successfully, but these errors were encountered:
memoise::has_cache()?
memoise::has_cache()
Sorry, something went wrong.
I didn't see that! Works as expected. Thanks for the hint!
No branches or pull requests
Is it possible to have a function
is_cached
that checks if a call is already in the cache?Something like this (doesn't work, as I don't fully understand the internals of
memoise()
).Even better: if the
is_cached
function is able to take the call to the memoised functionis_cached(myfun("Alice"))
.The text was updated successfully, but these errors were encountered: