passing ellipsis arguments to map function purrr package, R

后端 未结 3 1679
情歌与酒
情歌与酒 2020-12-19 14:55

I want to use ellipsis parameters inside map function of purrr package. this is a toy example:

f1<-function(x,a=NA,b=NA,prs=seq(0, 1, 0.25),SW=T){
  if(SW         


        
3条回答
  •  执笔经年
    2020-12-19 15:53

    You can also capture the ellipses early on in your second function, and use do.call to add them to your first function later on. This makes it more explicit where and how they are used.

    f2 <- function(df, ...){
      params <- list(...)
      res <- map_df(colnames(df), ~ do.call(
        f1, c(list(x = df[,.], a=.), params)))
      return(res)
    }
    

提交回复
热议问题