yang123
我暂时只会lapply()
这一招,或许你可以试试future.apply
包进行并行
library("future.apply")
#> 载入需要的程辑包:future
plan(multiprocess)
#> Warning: Strategy 'multiprocess' is deprecated in future (>= 1.20.0). Instead,
#> explicitly specify either 'multisession' or 'multicore'. In the current R
#> session, 'multiprocess' equals 'multisession'.
fun1<-function(x,y){x+y+10}
fun2<-function(x,y){x+y+1000}
fun3<-function(x,y){x+y+10000}
fun_list<-list(fun1,fun2,fun3)
future.apply::future_lapply(fun_list,function(z){z(x=2,y=0.1)})
#> [[1]]
#> [1] 12.1
#>
#> [[2]]
#> [1] 1002.1
#>
#> [[3]]
#> [1] 10002.1
<sup>Created on 2022-05-24 by the reprex package (v2.0.1)</sup>