-
Notifications
You must be signed in to change notification settings - Fork 56
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
unmemoise function? #36
Comments
R's semantics don't really support your example, you would have to
But if you don't want memoization why wouldn't you just call the original function directly? |
@jimhester I hope I am not adding noise to this discussion, but what about the following scenarios, where it would be desirable to temporarily switch off memoisation (while retaining the existing cache for later use)?:
In case 1, you'd also be spared the (typically low) overhead of memoisation. In case 2, a (contrived) example would be a function Moreover, including Would any of this warrant the creation of |
Hope you don't mind the outside comment, but isn't this possible by using a file system cache, or by just saving the specific memory cache (environment) as a variable and then using that when memoizing? You can just sum.cache <- cache_memory()
is.memoised(sum)
#> [1] FALSE
sum <- memoize(sum, cache= sum.cache)
is.memoised(sum)
#> [1] TRUE
has_cache(sum)( 1, 2, 3 )
#> [1] FALSE
sum( 1, 2, 3 )
#> [1] 6
has_cache(sum)( 1, 2, 3 )
#> [1] TRUE
rm(sum)
is.memoised(sum)
#> [1] FALSE
sum <- memoize(sum, cache= sum.cache)
has_cache(sum)( 1, 2, 3 )
#> [1] TRUE |
@jefferys I see your point, but that procedure won't work in general, unfortunately. You have removed the binding named |
I guess I don't understand what you mean. If the function to be memoised was not defined in the current scope/envionment, the memoised version hides it; the original was never changed by If the function to be memoised was defined in the current scope, replacing it with a redefinition of the same name seems like a bad idea. Why not just use a different name? But even if you do yo can get the original back using @jimhester's insider trick of There is also an |
@jefferys In your example, you reassign Getting the underlying function by directly accessing the environment of the memoised function works, of course, but it is not ideal because: 1) it's not declarative (of intent); 2) it depends on a detail of the current implementation of |
Firstly, this package is really great! Thanks for the development and support. I'm writing to see if there'd be interest in an
unmemoise(fn)
function which will then make sure that this will work:A usecase for this would be for example an interactive session where larger requests to the same functions might be suitable for caching but more granular requests might be better off run on real time data.
Has there been already any thought on such feature?
The text was updated successfully, but these errors were encountered: