我想可以选择非常精确地指定功能的行为(如果可能的话)。例如,
foo <- function() {}
Env <- new.env(parent=emptyenv())
environment(foo) <- Env
foo()
# Error in { : could not find function "{"
Env$`{` <- base::`{`
environment(foo) <- Env
foo()
# NULL
我知道我需要设置 foo
的环境
,并且在该环境中定义了任何 foo
的依赖(或该环境的环境父母,或父母的父母等)。但是,
- 必须指定所有必须指定什么
- 不能指定(即,在什么情况下我坚持默认行为)?
例如,在以下内容中,当我离开 bar
时,为什么没有错误,当我离开“ undefined)(什么样的东西是”
,还是”。
bar <- function() {""}
Env <- new.env(parent=emptyenv())
Env$`{` <- base::`{`
environment(bar) <- Env
bar()
# [1] ""
我的更大的练习是探索构建具有很多依赖性的非常大的系统,但没有循环依赖性的方法。我认为我将需要精确控制功能环境,以确保没有周期。我的目标是a 泥浆的泥浆我曾经写过的所有R代码(可能并非全部都在内存中,甚至在本地存储中),并且,每当我编写新代码时,都可以选择取决于我过去写的某些代码,我可以访问那个ealier代码。
相关文章包括:
[ dinters ],[ specify ]和[环境 - 安排框架”。
I would like to have the option of specifying very precisely (exactly, if possible) the behavior of functions. For example,
foo <- function() {}
Env <- new.env(parent=emptyenv())
environment(foo) <- Env
foo()
# Error in { : could not find function "{"
EnvI would like to have the option of specifying very precisely (exactly, if possible) the behavior of functions. For example,
{` <- base::`{`
environment(foo) <- Env
foo()
# NULL
I know I need to set the environment
of foo
, and that whatever foo
depends upon is defined in that environment (or that environment's parent, or the parent's parent, etc.). But
- what all must be specified, and
- what can't be specified (i.e., in what cases am I stuck with default behavior)?
For example, in the following, why is there no error when the call to bar
is attempted, when I leave "
undefined (what kind of a thing is "
, anyway? Or is it ""
?).
bar <- function() {""}
Env <- new.env(parent=emptyenv())
EnvI would like to have the option of specifying very precisely (exactly, if possible) the behavior of functions. For example,
foo <- function() {}
Env <- new.env(parent=emptyenv())
environment(foo) <- Env
foo()
# Error in { : could not find function "{"
EnvI would like to have the option of specifying very precisely (exactly, if possible) the behavior of functions. For example,
{` <- base::`{`
environment(foo) <- Env
foo()
# NULL
I know I need to set the environment
of foo
, and that whatever foo
depends upon is defined in that environment (or that environment's parent, or the parent's parent, etc.). But
- what all must be specified, and
- what can't be specified (i.e., in what cases am I stuck with default behavior)?
For example, in the following, why is there no error when the call to bar
is attempted, when I leave "
undefined (what kind of a thing is "
, anyway? Or is it ""
?).
{` <- base::`{`
environment(bar) <- Env
bar()
# [1] ""
My larger exercise is exploring ways to build very large systems with lots of dependencies, but no circular dependencies. I think I will need precise control over function environments in order to guarantee that there are no cycles. I am aiming for a ball of mud of sorts, where I can, given certain discipline, put all the R code I ever write into a single structure (which might not all be in memory, or even on local storage)—and, whenever I write new code, have the option of depending on some code I wrote in the past, provided that I have access to that ealier code.
Related posts include:
[distinct], [specify], and [environments-enclosures-frames].
发布评论