From 6404c76aac0c949d11b3c00c1a13f869e781abed Mon Sep 17 00:00:00 2001 From: joeroe Date: Sat, 29 Dec 2018 19:06:52 +0100 Subject: [PATCH] Add basic validation as suggested by tsdye (#1) --- R/graph.R | 21 +++++++++++++++++++++ man/is_valid_harris.Rd | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 man/is_valid_harris.Rd diff --git a/R/graph.R b/R/graph.R index 737dcf5..739b41b 100644 --- a/R/graph.R +++ b/R/graph.R @@ -23,4 +23,25 @@ harris <- function(data, context, relation) { tibble::tibble(to, from) %>% drop_na() %>% return() +} + +#' Validate stratigraphic graphs +#' +#' Checks whether a stratigraphic graph is a valid Harris matrix. +#' +#' @param stratgraph A stratigraphic graph. +#' @param warn Display warnings for invalid graphs (Default: `TRUE`). +#' +#' @return `TRUE` or `FALSE` +#' @export +#' +#' @examples +is_valid_harris <- function(stratgraph, warn = TRUE) { + if (!igraph::is.dag(stratgraph)) { + if(warn) warning("Invalid Harris matrix: graph contains cycles") + return(FALSE) + } + else { + return(TRUE) + } } \ No newline at end of file diff --git a/man/is_valid_harris.Rd b/man/is_valid_harris.Rd new file mode 100644 index 0000000..8746f7d --- /dev/null +++ b/man/is_valid_harris.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/graph.R +\name{is_valid_harris} +\alias{is_valid_harris} +\title{Validate stratigraphc graphs} +\usage{ +is_valid_harris(stratgraph, warn = TRUE) +} +\arguments{ +\item{stratgraph}{A stratigraphic graph.} + +\item{warn}{Display warnings for invalid graphs (Default: `TRUE`).} +} +\value{ +`TRUE` or `FALSE` +} +\description{ +Checks whether a stratigraphic graph is a valid Harris matrix. +}