R/verify_data.R

Defines functions verify_data

Documented in verify_data

#' Verify the integrity of the data object
#'
#' @inheritParams funky_heatmap
#'
#' @returns A verified data object
#'
#' @export
#'
#' @examples
#' library(tibble)
#' data <- tribble(
#'   ~id, ~name, ~x, ~y,
#'   "foo", "Foo", 0.5, 0.7,
#'   "bar", "Bar", 1.0, 0.1
#' )
#' verify_data(data)
verify_data <- function(data) {
  data <- if_list_to_tibble(data)

  if (is.matrix(data)) {
    data <- as.data.frame(data)
  }

  assert_that(
    is.data.frame(data),
    ncol(data) >= 1,
    nrow(data) >= 1
  )

  if (!data %has_name% "id" && !is.null(rownames(data))) {
    cli_alert_info("Could not find column 'id' in data. Using rownames as 'id'.")
    data <- data %>% rownames_to_column("id")
  }

  assert_that(
    data %has_name% "id"
  )

  data
}

Try the funkyheatmap package in your browser

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

funkyheatmap documentation built on April 11, 2025, 5:39 p.m.