How to call functions within a function appropriately

See the FAQ: How to do a minimal reproducible example reprex for beginners for a better way to include code examples.

won't work because it will return the closure, not the evaluation, because require three parameters and none have been provided.

func1 <- function(x) x + 1
#> [1] 2
func2 <- function(x) x + 2
#> [1] 3
func3 <- function(x) func1(x) + func2(x)
#> [1] 5
func4 <- function(x) return(func1)
#> function(x) x + 1
#> <bytecode: 0x560889df48f0>

Also, if the intent not is to transliterate matlab code into R but to solve the underlying calculation, there are probably functions to do this more easily.

1 Like