使用省略号...将参数传递给furrr :: future_map

问题描述

我试图在R中使用furrr::future_pmap替换另一个函数中的函数调用中的purrr::pmap

目前我已经设置好了,所以pmap使用省略号...传递了其他参数,但是当我尝试使用future_pmap进行此操作时,我得到了未使用的参数错误(请参见下面的示例) 。从这里的passing ellipsis arguments to map function purrr package,R和其他先前的研究中我知道,要使省略号与pmap一起使用,您需要使用function(x,y,z) blah(x,z,...)而不是~blah(..1,..2,..3),但是对于这种方法似乎不起作用future_map。进行这项工作还有其他秘密吗?

我创建了一个非常简单的reprex,显然,我的真实函数在future_pmap中运行更有意义

library(purrr)

library(furrr)
#> Loading required package: future
plan(multiprocess)

xd <- list(1,10,100)
yd <- list(1,2,3)
zd <- list(5,50,500)


sumfun <- function(indata,otherdata){
  out <- sum(c(indata,otherdata))
  
  return(out)
  
}



test_fun_pmap_tilde <- function(ind,...){
  
  return( pmap(ind,~sumfun(c(..1,..3),...)))
  
}
test_fun_pmap <- function(ind,function(x,z) sumfun(c(x,z),...)))
  
  
}


test_fun_future_pmap <- function(ind,...){
  
  return( future_pmap(ind,...)))
  
  
}

#doesn't work as need to use function(x,z) instead of tildes
test_fun_pmap_tilde(list(xd,yd,zd),otherdata = c(100,1000))
#> Error in sumfun(c(..1,...): unused arguments (.l[[2]][[i]],.l[[3]][[i]])

#this one works
test_fun_pmap(list(xd,1000))
#> [[1]]
#> [1] 1107
#> 
#> [[2]]
#> [1] 1162
#> 
#> [[3]]
#> [1] 1703

#but using future_pmap it doesn't work
test_fun_future_pmap(list(xd,1000))
#> Error in (function (x,z) : unused argument (otherdata = c(100,1000))
Created on 2020-08-31 by the reprex package (v0.3.0)

解决方法

好的,我找到了一种工作方式。显然我需要3套省略号而不是1套。

SELECT CLUB.id,CLUB.name,COUNT(TEAM.id) AS "#TEAMS",SUM( case TEAM.PAID_UP
                when true then 1
                else 0
              end case) AS "#PAID UP TEAMS",COUNT(TEAM.id) / SUM( case TEAM.PAID_UP
                when true then 1
                else 0
              end case) * 100 AS "%PAIDUP"
FROM CLUB
INNER JOIN TEAM
ON CLUB.ID = TEAM.CLUB_ID
GROUP BY CLUB.ID

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...