Skip to content
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

function to be memoised with argument that is function, which might be passed another memoised function #86

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bluaze
Copy link

@bluaze bluaze commented May 8, 2019

a function to be memoised, say f, has an argument fn that accepts function. If such argument fn is passed another memoised function, say gm <- memoise(g), the memoised f's cache may not hit as the hash in the memoised f would change when gm is executed with new arguments and new key-value pairs are stored to gm's cache and the hash digest not only the gm itself but also its enclosing environment, which contains the caching environment

here is an example

f <- function(x) x
g <- function(fn) {i <<- fn(i) + 1; i}
i <- 0

fm <- memoise(f)
gm <- memoise(g)

gm(fm)  # first time, would be 1
gm(fm)  # second time, depends on how fm is treated in hashing, preferably still be 1

to avoid hash the entire gm, the original g could be used instead, and to avoid g's own enclosing environment problem and srcref problem, as can be seen in #84, as.character(body(g)) might be more appropriate

@codecov-io
Copy link

Codecov Report

Merging #86 into master will decrease coverage by 17.46%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #86       +/-   ##
==========================================
- Coverage   77.37%   59.9%   -17.47%     
==========================================
  Files           5       5               
  Lines         221     222        +1     
==========================================
- Hits          171     133       -38     
- Misses         50      89       +39
Impacted Files Coverage Δ
R/memoise.R 100% <100%> (ø) ⬆️
R/cache_s3.R 0% <0%> (-100%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1650ad7...5cac987. Read the comment docs.

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