R: Like lazyload variables from inst / extdata in an R package

I have a helper.RData file in my inst / extdata that contains variables and data sets that will be used by functions in my package, but not intended for user access.

I load it at the beginning of the package using:

load(system.file("extdata","helper.RData", package = "mypackage"))

Since the file is large, it takes quite a lot of time, and it is especially annoying during development (I use a pretty graph function load_all()from the package devtools).

I would rather have it lazy boot, so that the file only downloads when it is really needed.

How can i do this?

+4
source share
1 answer

, , .

, tools:::makeLazyLoadDB, lazyLoad.

. , X Y, , :

e=new.env(parent=emptyenv())
e$X = X
e$Y = Y

:

tools:::makeLazyLoadDB(e,"DBNAME")

, DBNAME.

R, lazyLoad("DBNAME").

+3

Source: https://habr.com/ru/post/1525460/


All Articles