do.call specify environment inside function

前端 未结 3 2103
盖世英雄少女心
盖世英雄少女心 2021-02-09 14:11

I\'m using the following construct in a package,

## two functions in the global environment
funa <- function(x) x^2
funb <- function(x) x^3
## called withi         


        
3条回答
  •  日久生厌
    2021-02-09 14:25

    A slightly simpler version of @g-grothendieck's answer. Rather than using the function names, we just put the functions themselves into the list that is fed to lapply.

    fun_wrap1 <- function(){
      funa1 <- function(x) x^2
      funb1 <- function(x) x^3
      lapply(list(funa1, funb1), do.call, list(x=3))
    }
    
    fun_wrap1()
    

提交回复
热议问题