jsta / nhdR

R interface to the National Hydrography Dataset :droplet:
https://jsta.github.io/nhdR/
37 stars 12 forks source link

Fix memoised function to be .onLoad rather than at compile time #60

Closed jsta closed 4 years ago

jsta commented 4 years ago

It is recommended that functions in a package are not memoised at build-time, but when the package is loaded. The simplest way to do this is within \code{.onLoad()} with, for example

fun <- function() { some_expensive_process()

zzz.R .onLoad <- function(libname, pkgname) { fun <<- memoise::memoise(fun) }