8000 New function has.cache by dkesh · Pull Request #10 · r-lib/memoise · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

New function has.cache #10

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

Merged
merged 1 commit into from
Jan 22, 2016
Merged

New function has.cache #10

merged 1 commit into from
Jan 22, 2016

Conversation

dkesh
Copy link
@dkesh dkesh commented Mar 19, 2015

This commit creates a new function has.cache( f, ... ) that returns TRUE or FALSE

I use memoisation extensively for network operations. It is sometimes useful to me to use a slow API if it has already been cached and a faster API if the slow API has not been cached. In this case, I want to test whether a function has been cached without actually running it.

jimhester pushed a commit that referenced this pull request Jan 19, 2016
@jimhester jimhester merged commit 15bd87b into r-lib:master Jan 22, 2016
@jimhester
Copy link
Member

Thanks for the PR! I renamed this function has_cache() and modified the API, it now returns a modified memoized function that simply returns a boolean value if the arguments have a cached value. This simplified the implementation (which has become more complicated after merging #14) and gives you the same auto completion of arguments. So from your example you can now do the following.

mem_sum <- memoise(sum)
has_cache(mem_sum)(1, 2, 3) # FALSE
#> [1] FALSE
mem_sum(1, 2, 3)
#> [1] 6
has_cache(mem_sum)(1, 2, 3) # TRUE
#> [1] TRUE

@dkesh
Copy link
Author
dkesh commented Jan 22, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0