R/construct-s3.R

Defines functions construct.function

#' @export
construct.function <- function(data, defn, ...) {

  data %>%
    select(constructor_args(defn)) %>%
    transpose() %>%
    map(~exec(defn, !!!.))

}


#' @export
deconstruct.function <- function(objs, defn, ...) {

  map_dfr(
    objs,
    function(obj, args) {
      map(args, ~obj[[.]]) %>%
        set_names(args) %>%
        as_tibble_row()
    },
    args = constructor_args(defn)
  )

}
tjpalanca/dbtools documentation built on Oct. 7, 2021, 6:43 a.m.