[R-pkg-devel] define an environment in .onLoad
Pascal Title
p@@c@|t|t|e @end|ng |rom gm@||@com
Tue Jan 29 22:40:23 CET 2019
Hi,
I am developing an R package where I would like to have a set of names
defined once, and which could then be queried from within the various
functions of the package. The way I have currently set this up is to define
a new environment that contains these names.
So, what I currently have is:
.var <- new.env()
.var$bio <- "bio_"
.var$tmin <- "tmin_"
.var$tmax <- "tmax_"
What I would like is that this environment be created when the R package is
loaded. That way, default values are automatically in place, and if the
user would like to change the naming that they use for tmin, for example,
they would just need to do (for example):
.var$tmin <- ‘minTemp_'
And then these names can be accessed from within any of the functions, and
this is unlikely to conflict with any R objects the user is defining.
Where I am stuck is how/where to define this new environment such that it
is made available when the package is loaded. I tried including the
following in R/zzz.R:
.onLoad <- function(libname, pkgname) {
# define a custom environment for defining the naming of variables
.var <- new.env()
# default
.var$bio <- "bio_"
.var$tmin <- "tmin_"
.var$tmax <- "tmax_"
invisible()
}
But if I build/install the package, the .var environment is not already
created. Any suggestions?
Thanks!
-Pascal
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list