功能环境的精确规范

发布于 2025-01-25 20:33:44 字数 1448 浏览 1 评论 0 原文

我想可以选择非常精确地指定功能的行为(如果可能的话)。例如,

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 "{"
Env

I 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())
Env

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 "{"
Env

I 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].

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文