In R, when want to use one/multiple functions inside another function, maybe there are two ways. An example function can be:
Method 1:
make.power <- function(n) {
pow <- function(x) {
x^n
}
pow
}
Method 2:
make.power <- function(n) {
pow(n)
}
pow <- function(x) {
x^n
}
In my opinion (but I am not sure), the second method is a better way if you have lots of child functions for the parent one.
My questions are: 1) Are there any functional differences between the two ways? E.g., how the function will pass variables, or the relationship between the children and parent functions, etc..
2) which one might be a preferred one (maybe more computational efficient or structurally clear) for R?