r-lib / memoise

Easy memoisation for R
https://memoise.r-lib.org
Other
317 stars 56 forks source link

Allow formulas to depend on function arguments? #124

Open DarwinAwardWinner opened 3 years ago

DarwinAwardWinner commented 3 years ago

I have a function that I am memoising, which reads information from a file. Specifically, it reads a 7 GB JSON file and only keeps a small part of it. The function takes the file name as an argument, and I'd like to be able to invalidate the cache if the contents of the file change even if the file name is the same (e.g. I want the cache value to depend on file.info(filename). However, it seems that with the current interface there is no way to accomplish this, because the additional formulae provided to memoise in ... cannot refer to the function's arguments. Is there any way to change this, e.g. evaluating the formulae in an environment containing the function's arguments?