R/get_body.R

Defines functions get_body.event_list get_body.event get_body

Documented in get_body

#' @title Get Event Body
#'
#' @description This function returns the body of an event or list of events.
#'
#' @param obj An event or a list of events.
#'
#' @return The \code{get_body} function returns a list object
#'
#' @examples
#'
#' first_event <- event(
#'   id = 'first-event',
#'   type = 'FIRST_EVENT',
#'   time = Sys.time(),
#'   attr_01 = 'first-body-attr',
#'   attr_02 = 'second-body-attr'
#' )
#'
#' get_body(first_event)
#'
#' @importFrom purrr map
#' @export
get_body <- function(obj) UseMethod("get_body")

#' @export
get_body.event <- function(obj) obj[["body"]]

#' @export
get_body.event_list <- function(obj){
  bodys <- purrr::map(obj, get_body)
  return(bodys)
}

Try the eventr package in your browser

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

eventr documentation built on July 8, 2020, 7:32 p.m.