R/data_eval.R

Defines functions data_eval

#' Create tibbles from user objects and/or user data
#'
#' @param data A data.frame/tibble, or NULL
#' @param ... Arguments are passed to \link[dplyr]{transmute} if \code{data} is
#'   present, and \link[tibble]{tibble} if it is not.
#'
#' @return A \link[tibble]{tibble} with the results of ...
#' @noRd
#' @importFrom rlang !!!
#'
data_eval <- function(.data = NULL, ...) {
  args <- rlang::quos(...)
  # discard NULLs, which tibble doesn't accept and transmute complains about
  args <- args[!vapply(args, identical, FUN.VALUE = logical(1), rlang::quo(NULL))]

  if(is.null(.data)) {
    tibble::tibble(!!!args)
  } else {
    tibble::as_tibble(dplyr::transmute(.data, !!!args))
  }
}
paleolimbot/carbon14 documentation built on May 25, 2019, 11:33 p.m.