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

Worth warning about memoising random functions #63

Open
MCMaurer opened this issue Feb 13, 2018 · 1 comment
Open

Worth warning about memoising random functions #63

MCMaurer opened this issue Feb 13, 2018 · 1 comment

Comments

@MCMaurer
Copy link

MCMaurer commented Feb 13, 2018

Hey there,

This isn't necessarily a problem with memoise at all, but rather a warning that might be worth giving to folks who read about the package.

If someone tries to memoise a function that includes any sort of randomization in it, their outputs will not be random if the inputs are identical, and it could be really hard to tell just by looking at the results. Here's a simple example:

rnorm_mem <- memoise(rnorm)
x <- rnorm_mem(10)
y <- rnorm_mem(10)
all.equal(x,y)
#> [1] TRUE

It seems pretty obvious, but I could definitely see someone getting a little trigger-happy with memoise and making this mistake without realizing it.

@katrinleinweber
Copy link

Does this also occur, if the memoised function receives inputs in a random order? Would explain #106.

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

No branches or pull requests

4 participants