Reputation: 338
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.
Upvotes: 0
Views: 308
Reputation: 72731
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)
}
Upvotes: 4