From 7cf7a4db35d00cce8a0b2d7d83231d995f492393 Mon Sep 17 00:00:00 2001 From: Neves-P Date: Thu, 25 Mar 2021 19:11:59 +0100 Subject: [PATCH] Add is_daisie_object() WIP. Progress #7 --- R/is_daisie_object.R | 34 ++++++++++++++++++++++++++++++++++ man/is_daisie_object.Rd | 14 ++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 R/is_daisie_object.R create mode 100644 man/is_daisie_object.Rd diff --git a/R/is_daisie_object.R b/R/is_daisie_object.R new file mode 100644 index 0000000..8488b8f --- /dev/null +++ b/R/is_daisie_object.R @@ -0,0 +1,34 @@ +#' Checks if object is a [DAISIE] simulation object +#' +#' @inheritParams default_params_doc +#' +#' @return `TRUE` if `data` is a valid [DAISIE] object, `FALSE` if not. +#' @export +#' +#' @examples +is_daisie_object <- function(data) { + if (!is.list(data)) { + return(FALSE) + } + + first_element_lengths <- vapply(X = lapply(data, `[[`, 1), length, numeric(1)) + if (!all(first_element_lengths == 3)) { + return(FALSE) + } + + first_element_names <- unlist(lapply(X = lapply(data, `[[`, 1), FUN = names)) + first_expected_names <- c("island_age", "not_present", "stt_all") + if (!all(first_element_names %in% expected_names)) { + return(FALSE) + } + + # stt_tables <- lapply(lapply(data, `[[`, 1), FUN = function(x) x$stt_all) + # n_extant_species <- lapply(stt_tables, function(x) sum(x[nrow(x), ])) + # have_extant_species <- which(n_extant_species != 0) + # second_expected_names <- c("branching_times", "stac", "missing_species") + + + + +} + diff --git a/man/is_daisie_object.Rd b/man/is_daisie_object.Rd new file mode 100644 index 0000000..7aebec8 --- /dev/null +++ b/man/is_daisie_object.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is_daisie_object.R +\name{is_daisie_object} +\alias{is_daisie_object} +\title{Checks if object is a \link{DAISIE} simulation object} +\usage{ +is_daisie_object(data) +} +\value{ +\code{TRUE} if \code{data} is a valid \link{DAISIE} object, \code{FALSE} if not. +} +\description{ +Checks if object is a \link{DAISIE} simulation object +}