How to do.call a dplyr function

Hi brodriguesco,

Quoting mpg, as before, does not work either

Apparently it works on my side:

library(dplyr)

purely <- function(.f){
  
  function(..., .log = "Log start..."){
    
    res <- tryCatch(
      do.call(.f, list(...)),
      condition = function(cnd) cnd
    )
    
    suppressWarnings(
      res$result <- if(all(c("message", "call") %in% names(res))){
        NA
      } else {
        res
      }
    )
    
    list(result = res$result,
         log = res$message)
    
  }
}


purely(select)(mtcars, "mpg")
#> $result
#>                      mpg
#> Mazda RX4           21.0
#> Mazda RX4 Wag       21.0
#> Datsun 710          22.8
#> Hornet 4 Drive      21.4
#> Hornet Sportabout   18.7
#> Valiant             18.1
#> Duster 360          14.3
#> Merc 240D           24.4
#> Merc 230            22.8
#> Merc 280            19.2
#> Merc 280C           17.8
#> ...
#>
#> $log
#> NULL

Have you tried defusing mpg? Like:

purely(select)(mtcars, expr(mpg))

#> $result
#>                      mpg
#> Mazda RX4           21.0
#> Mazda RX4 Wag       21.0
#> Datsun 710          22.8
#> Hornet 4 Drive      21.4
#> Hornet Sportabout   18.7
#> Valiant             18.1
#> Duster 360          14.3
#> Merc 240D           24.4
#> Merc 230            22.8
#> ...
#> 
#> $log
#> NULL
1 Like