嵌套函数:“错误:找不到嵌套函数”

发布于 2025-01-08 01:02:58 字数 267 浏览 1 评论 0原文

我正在定义一个具有嵌套函数的函数,如下所示:

 afunc <- function(p1, p2) { 

 for loop {
   f = bfunc(p1)
 }
 g = cfunc(p2)

 bfunc <- function(p3) {
   ...
 }

 cfunc <-function(p4){
  ...
 }

}

出于某种原因,我收到“错误:找不到函数“bfunc””。我在这里错过了什么吗?提前致谢。

I am defining a function which has nested functions, like the following:

 afunc <- function(p1, p2) { 

 for loop {
   f = bfunc(p1)
 }
 g = cfunc(p2)

 bfunc <- function(p3) {
   ...
 }

 cfunc <-function(p4){
  ...
 }

}

For some reason, I am getting "ERROR: Could not find function "bfunc"". Am I missing something here? Thanks in advance.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咋地 2025-01-15 01:02:58

您需要将函数定义移至其执行位置之前:

afunc <- function(p1, p2) { 
 bfunc <- function(p3) {
   ...
 }

 cfunc <-function(p4){
  ...
 }

 for loop {
   f = bfunc(p1)
 }
 g = cfunc(p2)


}

You need to move your function definition to before where it executes:

afunc <- function(p1, p2) { 
 bfunc <- function(p3) {
   ...
 }

 cfunc <-function(p4){
  ...
 }

 for loop {
   f = bfunc(p1)
 }
 g = cfunc(p2)


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文