Skip to content

Commit

Permalink
Add is_daisie_object() WIP. Progress #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Neves-P committed Mar 25, 2021
1 parent 530d648 commit 7cf7a4d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
34 changes: 34 additions & 0 deletions R/is_daisie_object.R
Original file line number Diff line number Diff line change
@@ -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")




}

14 changes: 14 additions & 0 deletions man/is_daisie_object.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cf7a4d

Please sign in to comment.