environment               package:base               R Documentation

_E_n_v_i_r_o_n_m_e_n_t _A_c_c_e_s_s

_D_e_s_c_r_i_p_t_i_o_n:

     Get, set, test for and create environments.

_U_s_a_g_e:

     environment(fun = NULL)
     environment(fun) <- value
     is.environment(obj)
     .GlobalEnv
     globalenv()
     new.env(hash=FALSE, parent=parent.frame())
     parent.env(env)
     parent.env(env) <- value

_A_r_g_u_m_e_n_t_s:

     fun: a `function', a `formula', or `NULL', which is the default.

   value: an environment to associate with the function

     obj: an arbitrary R object.

    hash: a logical, if `TRUE' the environment will be hashed

  parent: an environment to be used as the parent of the environment
          created.

     env: an environment

_D_e_t_a_i_l_s:

     The global environment `.GlobalEnv' is the first item on the
     search path, more often known as the user's workspace.  It can
     also be accessed by `globalenv()'.

     The variable `.BaseNamespaceEnv' is part of some experimental
     support for name space management.

     The assignment function `parent.env<-' is extremely dangerous as
     it can be used to destructively change environments in ways that
     violate assumptions made by the internal C code.  It may be
     removed in the near future.

_V_a_l_u_e:

     If `fun' is a function or a formula then `environment(fun)'
     returns the environment associated with that function or formula.
     If `fun' is `NULL' then the current evaluation environment is
     returned.

     The assignment form sets the environment of the function or
     formula `fun' to the `value' given.

     `is.environment(obj)' returns `TRUE' iff `obj' is an
     `environment'.

     `new.env' returns a new (empty) environment enclosed in the
     parent's environment, by default.

     `parent.env' returns the parent environment of its argument.

     `parent.env<-' sets the parent environment of its first argument.

_S_e_e _A_l_s_o:

     The `envir' argument of `eval'.

_E_x_a_m_p_l_e_s:

     ##-- all three give the same:
     environment()
     environment(environment)
     .GlobalEnv

     ls(envir=environment(approxfun(1:2,1:2, method="const")))

     is.environment(.GlobalEnv)# TRUE

     e1 <- new.env(TRUE, NULL)
     e2 <- new.env(FALSE, NULL)
     assign("a", 3, env=e2)
     parent.env(e1) <- e2
     get("a", env=e1)

