[Rd] what is the preferred method to create a package local variable?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Mar 31 19:09:48 CEST 2009


Look at the zzz.R file in the lattice package and the .LatticeEnv
variable in particular.
Also, when running lattice try this and look for .LatticeEnv in the output:

ls(asNamespace("lattice"), all = TRUE)


On Tue, Mar 31, 2009 at 11:45 AM, Whit Armstrong
<armstrong.whit at gmail.com> wrote:
> for the moment, I'm using:
>
> .onAttach <- function(libname, pkgname) {
>    .bbg.db.conn <<- dbConnect(dbDriver("PostgreSQL"), user="blah","blah")
> }
>
> .onUnload <- function(libpath) {
>    dbDisconnect(.bbg.db.conn)
> }
>
>
> which results in a hidden global variable in the global environment.
>
> I would prefer to make the assignment only in the package namespace.
> I've looked at assignInNamespace, but I can't seem to make it work.
>
> Is there a preferred method for doing this?
>
> When I try adding an assignment directly in the source file, I get the
> "cannot change value of locked binding" error.
>
> What am I missing?
>
> Thanks,
> Whit
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list