Variables and environment: How to make variables calculated from a function accessible to its subfunction automatically?

have a function that is


z = a+b

g = c+d

h <- function2(x,y)

} where function2 is in another file such that

function2<- function(x,y){

h <- x + z + g + y



How can I share an environment with function1 such that function2 knows im talking about z and g in function1? The problem is I have too many variables from function1 actually so I want function2 to know that some variables in their function comes from function1...

I tried using environment(function2) <- environment() before the h <- function2(x,y) line in function1 but it doesnt seem to work. Would appreciate any insights on this! thanks!

Best practice is to not attempt to do this.
If a function is intended to rely on values from a calling function, it should receive them as arguments from the calling function.

Thank you [nirgrahamuk]!

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.