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 [transmute][dplyr::transmute] if `data` is
#'   present, and [tibble][tibble::tibble] if it is not.
#'
#' @return A [tibble][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))
  }
}

Try the tidypaleo package in your browser

Any scripts or data that you put into this service are public.

tidypaleo documentation built on Jan. 22, 2023, 1:13 a.m.