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

Missing example for ... parameter to memoise #136

Open
kent37 opened this issue Feb 22, 2022 · 1 comment
Open

Missing example for ... parameter to memoise #136

kent37 opened this issue Feb 22, 2022 · 1 comment

Comments

@kent37
Copy link

kent37 commented Feb 22, 2022

The documentation for the ... parameter for memoise says to "See Examples for usage." There don't seem to be any usage examples here. The parameter is used in the example for timeout but there is no additional explanation of how to use it.

#' caching, specified as one-sided formulas (no LHS). See Examples for usage.

@lgaborini
Copy link

I was being curious on the same topic.
It this how it should work?

The ... are additional parameters that may invalidate the cache when they change their values.
These are evaluated when the memoised function is called (hence the reason for supplying it as a formula).
In this case, the argument dt changes value every 3 seconds.

library(memoise)

a <- function(n) { runif(n) }
memA <- memoise(a, dt = ~timeout(3))


memA(3)
#> [1] 0.7704398 0.2082827 0.1184781
memA(3)
#> [1] 0.7704398 0.2082827 0.1184781
memA(3)
#> [1] 0.7704398 0.2082827 0.1184781
Sys.sleep(5)
memA(3)
#> [1] 0.38938505 0.06540492 0.72489978
memA(3)
#> [1] 0.38938505 0.06540492 0.72489978

Created on 2024-01-18 with reprex v2.1.0

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

No branches or pull requests

2 participants