Skip to content
Prev 40369 / 63421 Next

assignInNamespace and new bindings

Le 31/05/11 12:01, Prof Brian Ripley a ?crit :
Sure.

I'll just keep using this small workaround, unexported from the next Rcpp:

# just like assignInNamespace but first checks that the binding exists 

forceAssignInNamespace <- function( x, value, env ){
     is_ns <- isNamespace( env )
     if( is_ns && exists( x, env ) && bindingIsLocked(x, env ) ){
         unlockBinding( x, env )
     }

     assign( x, value, env )

     if( is_ns ){
         lockBinding( x, env )
     }
}

I find this useful for when a package wants to assign in its own namespace.

Romain