[R] No visible bindings and assignement to the global environment
Fabien Fivaz
fabien.fivaz at unine.ch
Mon Dec 15 18:28:25 CET 2014
Hi everyone,
I'm sure this question has been asked before, but I'm unable to find a
definitive answer (if there is any). I've been trying to put back to
CRAN a package (grasp-r). The package uses many functions that share a
lot of common variables. For instance, a model call is created by the
first function and then used through all the modeling process, some
functions change it with :
/assign("MODELCALL", MODELCALL, envir = .GlobalEnv)/
some just use it without being explicitely called in the function
arguments. The assignement is explicitely against the CRAN policies (Do
not alter the user's workspace). The use of variables raises a warning
when building the package : "no visible binding for global variable
‘MODELCALL’".
BTW, the old school "double" assignement
/MODELCALL <<- MODELCALL/
works but raises a similar warning "no visible binding for '<<-'
assignment to ‘MODELCALL’" And I understand that it is also against CRAN
policies to use the double assignement.
Many user groups, examples et al. point to R environments. I could
create a new.env() in the first function (initializing function), and
assign all subsequent variables to it. Something like
/
/dummy<-function (a) //
//{//
// dummy.env <- new.env()//
// assign("a", a, envir=dummy.env)//
// return(dummy.env)//
//}/
/ and a call_that_variable_back function :/
/dummy2<-function () //
//{//
// b<-get("a",envir=dummy.env)//
// b//
//}//
/
/It works, except that I have to put a enormous sign saying : don't call
your env anything else than dummy.env...
What do you use ? Is there a best practice for that type of problem ?
Thanks in advance for your help, best wishes
Fabien
--
Fabien Fivaz
Centre suisse de cartographie de la faune
Passage Max.-Meuron 6
CH - 2000 Neuchâtel
Switzerland
Tel. +41 32 725 72 57
fabien.fivaz at unine.chv
/", a, envir=dummy.env)//
// return(dummy.env)//
//}/
and a call_that_variable_back function :
/dummy2<-function () //
//{//
// b<-get("b",envir=dummy.env)//
// b//
//}//
/
It works, except that I have to put a enormous sign saying : don't call
your env anything else than dummy.env...
What do you use ? Is there a best practice for that type of problem ?
Thanks in advance for your help, best wishes
Fabien
--
Fabien Fivaz
Centre suisse de cartographie de la faune
Passage Max.-Meuron 6
CH - 2000 Neuchâtel
Switzerland
Tel. +41 32 725 72 57
fabien.fivaz at unine.chv
[[alternative HTML version deleted]]
More information about the R-help
mailing list