Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

bindenv: Binding and Environment Locking, Active Bindings

bindenvR Documentation

Binding and Environment Locking, Active Bindings

Description

These functions represent an interface for adjustmentsto environments and bindings within environments. They allow forlocking environments as well as individual bindings, and for linkinga variable to a function.

Usage

lockEnvironment(env, bindings = FALSE)environmentIsLocked(env)lockBinding(sym, env)unlockBinding(sym, env)bindingIsLocked(sym, env)makeActiveBinding(sym, fun, env)bindingIsActive(sym, env)activeBindingFunction(sym, env)

Arguments

env

an environment.

bindings

logical specifying whether bindings should be locked.

sym

a name object or character string.

fun

a function taking zero or one arguments.

Details

The functionlockEnvironment locks its environment argument.Locking theenvironment prevents adding or removing variable bindings from theenvironment. Changing the value of a variable is still possible unlessthe binding has been locked. The namespace environments of packageswith namespaces are locked when loaded.

lockBinding locks individual bindings in the specifiedenvironment. The value of a locked binding cannot be changed. Lockedbindings may be removed from an environment unless the environment islocked.

makeActiveBinding installsfun in environmentenvso that getting the value ofsym callsfun with noarguments, and assigning tosym callsfun with oneargument, the value to be assigned. This allows the implementation ofthings like C variables linked toR variables and variables linked todatabases, and is used to implementsetRefClass. It mayalso be useful for making thread-safe versions of some system globals.Currently active bindings are not preserved during package installation,but they can be created in.onLoad.

Value

ThebindingIsLocked andenvironmentIsLocked return alength-one logical vector. The remaining functions returnNULL, invisibly.

Author(s)

Luke Tierney

Examples

# locking environmentse <- new.env()assign("x", 1, envir = e)get("x", envir = e)lockEnvironment(e)get("x", envir = e)assign("x", 2, envir = e)try(assign("y", 2, envir = e)) # error# locking bindingse <- new.env()assign("x", 1, envir = e)get("x", envir = e)lockBinding("x", e)try(assign("x", 2, envir = e)) # errorunlockBinding("x", e)assign("x", 2, envir = e)get("x", envir = e)# active bindingsf <- local( {    x <- 1    function(v) {       if (missing(v))           cat("get\n")       else {           cat("set\n")           x <<- v       }       x    }})makeActiveBinding("fred", f, .GlobalEnv)bindingIsActive("fred", .GlobalEnv)fredfred <- 2fred

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp