environment(base)
environment()所属R语言包:base
Environment Access
环境准入
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Get, set, test for and create environments.
获取,设置,测试和创造环境。
用法----------Usage----------
environment(fun = NULL)
environment(fun) <- value
is.environment(x)
.GlobalEnv
globalenv()
.BaseNamespaceEnv
emptyenv()
baseenv()
new.env(hash = TRUE, parent = parent.frame(), size = 29L)
parent.env(env)
parent.env(env) <- value
environmentName(env)
env.profile(env)
参数----------Arguments----------
参数:fun
a function, a formula, or NULL, which is the default.
function,formula或NULL,这是默认的。
参数:value
an environment to associate with the function
与功能相关联的环境
参数:x
an arbitrary R object.
任意一个R对象。
参数:hash
a logical, if TRUE the environment will use a hash table.
一个逻辑,如果TRUE环境将使用一个哈希表。
参数:parent
an environment to be used as the enclosure of the environment created.
创建环境的外壳被用来作为一个环境。
参数:env
an environment
环境
参数:size
an integer specifying the initial size for a hashed environment. An internal default value will be used if size is NA or zero. This argument is ignored if hash is FALSE.
整数指定为散列环境的初始大小。内部的默认值将被用来size如果是NA或零。 hash如果是FALSE,则忽略此参数。
Details
详情----------Details----------
Environments consist of a frame, or collection of named objects, and a pointer to an enclosing environment. The most common example is the frame of variables local to a function call; its enclosure is the environment where the function was defined. The enclosing environment is distinguished from the parent frame: the latter (returned by parent.frame) refers to the environment of the caller of a function. Since confusion is so easy, it is best never to use "parent" in connection with an environment (despite the presence of the function parent.env).
环境包括一个框架,或命名对象的集合,一个封闭的环境指针。最常见的例子是调用函数的局部变量的框架,它的外壳是在函数定义的环境。封闭的环境,是区别于父框架:后者(parent.frame返回)是指一个函数的调用者的环境。由于混乱是很容易,最好是从未使用在与环境有关的“家长”(尽管存在的功能parent.env)。
When get or exists search an environment with the default inherits = TRUE, they look for the variable in the frame, then in the enclosing frame, and so on.
当get或exists搜索默认环境inherits = TRUE,他们寻找的变量的框架,然后在封闭的框架,等等。
The global environment .GlobalEnv, more often known as the user's workspace, is the first item on the search path. It can also be accessed by globalenv(). On the search path, each item's enclosure is the next item.
全球环境.GlobalEnv,更经常为用户的工作空间,是搜索路径上的第一个项目。它也可以访问globalenv()。搜索路径上,每个项目的外壳是下一个项目。
The object .BaseNamespaceEnv is the namespace environment for the base package. The environment of the base package itself is available as baseenv().
.BaseNamespaceEnv对象是为基础包的命名空间环境。基地包本身的环境是可用baseenv()。
If one follows the chain of enclosures found by repeatedly calling parent.env from any environment, eventually one reaches the empty environment emptyenv(), into which nothing may be assigned.
如果一个如下一边喊parent.env从任何环境中,最后一个到达的空环境emptyenv(),融入其中没有可分配的链罩。
The replacement 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.
更换功能parent.env<-是极其危险的,因为它可以用于破坏性改变内部的C代码假设的方式违反环境。在不久的将来可能会被删除。
The replacement form of environment, is.environment, baseenv, emptyenv and globalenv are primitive functions.
environment,is.environment,baseenv,emptyenv和globalenv是原始的功能替代形式。
System environments, such as the base, global and empty environments, have names as do the package and namespace environments and those generated by attach(). Other environments can be named by giving a "name" attribute, but this needs to be done with care as environments have unusual copying semantics.
系统环境,如基地,全球和空的环境,有名字一样的包和命名空间环境和attach()产生的。其他环境中可以被命名为给予"name"属性,但是这需要小心做环境有不寻常的复制语义。
值----------Value----------
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.
如果fun然后是一个函数或公式environment(fun)返回,函数或公式的环境。如果funNULL那么目前的评估环境,则返回。
The replacement form sets the environment of the function or formula fun to the value given.
更换的形式设置的函数或公式fun的value定的环境。
is.environment(obj) returns TRUE if and only if obj is an environment.
is.environment(obj)回报TRUE obj当且仅当environment。
new.env returns a new (empty) environment with (by default) enclosure the parent frame.
new.env返回一个新的环境(空)(默认)外壳父框架。
parent.env returns the enclosing environment of its argument.
parent.env返回其参数的封闭环境。
parent.env<- sets the enclosing environment of its first argument.
parent.env<-设置了它的第一个参数的封闭环境。
environmentName returns a character string, that given when the environment is printed or "" if it is not a named environment.
environmentName返回一个字符串,打印环境时,或""如果它不是一个命名的环境。
env.profile returns a list with the following components: size the number of chains that can be stored in the hash table, nchains the number of non-empty chains in the table (as reported by HASHPRI), and counts an integer vector giving the length of each chain (zero for empty chains). This function is intended to assess the performance of hashed environments. When env is a non-hashed environment, NULL is returned.
env.profile返回以下组件列表:size链,可以存储在哈希表中的数量nchains表中的非空链(报告HASHPRI),counts整数向量,给每个链的长度(空链零)。此功能旨在评估散列环境的性能。当env是一个非哈希环境,NULL返回。
参见----------See Also----------
For the performance implications of hashing or not, see http://en.wikipedia.org/wiki/Hash_table.
对于散列的性能的影响或不,看到http://en.wikipedia.org/wiki/Hash_table的。
The envir argument of eval, get, and exists.
envireval参数,get和exists。
ls may be used to view the objects in an environment, and hence ls.str may be useful for an overview.
,ls可以用来查看对象的环境中,因此ls.str可能是有用概述。
sys.source can be used to populate an environment.
sys.source可以用来填充的环境。
举例----------Examples----------
f <- function() "top level function"
##-- all three give the same:[ - 所有提供相同的:]
environment()
environment(f)
.GlobalEnv
ls(envir=environment(stats::approxfun(1:2,1:2, method="const")))
is.environment(.GlobalEnv) # TRUE[真]
e1 <- new.env(parent = baseenv()) # this one has enclosure package:base.[这其中有外壳包:基地。]
e2 <- new.env(parent = e1)
assign("a", 3, envir=e1)
ls(e1)
ls(e2)
exists("a", envir=e2) # this succeeds by inheritance[成功通过继承]
exists("a", envir=e2, inherits = FALSE)
exists("+", envir=e2) # this succeeds by inheritance[成功通过继承]
eh <- new.env(hash = TRUE, size = NA)
with(env.profile(eh), stopifnot(size == length(counts)))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|