richfitz / storr

:package: Object cacher for R
http://richfitz.github.io/storr
Other
116 stars 10 forks source link

best practice for multi-argument hook #36

Closed fmichonneau closed 6 years ago

fmichonneau commented 7 years ago

Is there a way to do something like?

st <- storr_external(driver_rds("data/foo"), ff)

ff <- function(key, namespace, some_other_data) {
   # some calculation that depends on some_other_data
}

In normal code, I could put some_other_data inside the ff function, but in this particular case some_other_data is a target from a remake project that takes a long time to compute.

richfitz commented 7 years ago

Can you do this via a closure? Something like:

make_hook <- function(some_other_data) {
  force(some_other_data)
  function(key, namespace) {
    # some function that uses some_other_data?
  }
}

Otherwise, I'm sure something could be done. The implementation for the external storr is quite small so it would be easy enough to build from that to fit your use case better