R/assertions.R

Defines functions assert_nest_df check_nest_data

# -----------------------------common-assertions--------------------------------
check_nest_data <- function(.data, .nest_data) {
  
  x <- dplyr::pull(.data, {{ .nest_data }})
  
  if (!missing(x)) {
    
    assert_nest_df(x)
    
  } else {
    
    rlang::abort("argument \".nest_data\" is missing, with no default")
    
  }
  
}


assert_nest_df <- function(x) {
  
  assertthat::assert_that(
    assertthat::are_equal(class(x), "list"),
    msg = "argument `.nest_data` must be of class \"list\"."
  )
  
  assertthat::assert_that(
    assertthat::are_equal(class(x[1][[1]]), c("tbl_df", "tbl", "data.frame")) ||
      assertthat::are_equal(class(x[1][[1]]), c("grouped_df", "tbl_df", "tbl", "data.frame")) ||
      assertthat::are_equal(class(x[1][[1]]), c("spec_tbl_df", "tbl_df", "tbl", "data.frame")),
    msg = "argument `.nest_data` msut be of class \"grouped_df\", \"tbl_df\", \"tbl\", \"data.frame\"."
  )
  
}

Try the nplyr package in your browser

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

nplyr documentation built on Feb. 16, 2023, 7:24 p.m.