Skip to content
Prev 42421 / 398506 Next

Set values in namespaces

On Mon, 5 Jan 2004, Thomas Stabla wrote:

            
Base is a special case, and

assign("pi", 3.14, envir=NULL)

will do this (although please don't).

All other namespaces are sealed, so you will get something like
Error in assign("lda", pi, pos = 2) : can't change value of a locked binding

Now, that attempts to change the export, and not the value in the
namespace, so there is a question of which you want and why you want to
change it.  (Changing the value in the namespace does not change the
export, which is a copy, but as _both_ the namespace and exports
environments are sealed, this would not matter much.)

There are ways around this and if you peruse the R sources you will find 
them.  For example, grid sets up an environment in its namespace for its 
global variables, and in R-devel there is assignInNamespace().