Skip to content

New function has.cache#10

Merged
jimhester merged 1 commit into
r-lib:masterfrom
dkesh:master
Jan 22, 2016
Merged

New function has.cache#10
jimhester merged 1 commit into
r-lib:masterfrom
dkesh:master

Conversation

@dkesh

@dkesh dkesh commented Mar 19, 2015

Copy link
Copy Markdown

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
Copy Markdown
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

dkesh commented Jan 22, 2016

Copy link
Copy Markdown
Author

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