Rev 27625 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{environment}\alias{environment}\alias{environment<-}\alias{.GlobalEnv}\alias{globalenv}\alias{is.environment}\alias{new.env}\alias{parent.env}\alias{parent.env<-}\alias{.BaseNamespaceEnv}\title{Environment Access}\description{Get, set, test for and create environments.}\usage{environment(fun = NULL)environment(fun) <- valueis.environment(obj).GlobalEnvglobalenv()new.env(hash=FALSE, parent=parent.frame())parent.env(env)parent.env(env) <- value}\arguments{\item{fun}{a \code{\link{function}}, a \code{\link[stats]{formula}}, or\code{NULL}, which is the default.}\item{value}{an environment to associate with the function}\item{obj}{an arbitrary \R object.}\item{hash}{a logical, if \code{TRUE} the environment will be hashed}\item{parent}{an environment to be used as the parent of theenvironment created.}\item{env}{an environment}}\value{If \code{fun} is a function or a formula then \code{environment(fun)}returns the environment associated with that function or formula.If \code{fun} is \code{NULL} then the current evaluation environment isreturned.The assignment form sets the environment of the function or formula\code{fun} to the \code{value} given.\code{is.environment(obj)} returns \code{TRUE} iff \code{obj} is an\code{environment}.\code{new.env} returns a new (empty) environment enclosed in theparent's environment, by default.\code{parent.env} returns the parent environment of its argument.\code{parent.env<-} sets the parent environment of its first argument.}\details{The global environment \code{.GlobalEnv} is the first item on thesearch path, more often known as the user's workspace. It can also beaccessed by \code{globalenv()}.The variable \code{.BaseNamespaceEnv} is part of some experimentalsupport for name space management.The replacement function \code{parent.env<-} is extremely dangerous asit can be used to destructively change environments in ways thatviolate assumptions made by the internal C code. It may be removedin the near future.\code{is.environment} is generic: you can write methods to handlespecific classes of objects, see \link{InternalMethods}.}\seealso{The \code{envir} argument of \code{\link{eval}}.}\examples{##-- all three give the same:environment()environment(environment).GlobalEnvls(envir=environment(approxfun(1:2,1:2, method="const")))is.environment(.GlobalEnv)# TRUEe1 <- new.env(TRUE, NULL)e2 <- new.env(FALSE, NULL)assign("a", 3, env=e2)parent.env(e1) <- e2get("a", env=e1)}\keyword{data}\keyword{programming}