R/helpers.R

Defines functions .is_valid_snakemake_digraph .is_dot

.is_dot <- function(x){

  ## The first line should open the dot structure
  opens <- grepl("\\{$", x[[1]])
  ## The last line should close the dot structure
  ## In between can be empty
  closes <- grepl("^\\}", x[[length(x)]])
  hasType <- grepl("^(digraph|graph)", x[[1]])
  all(opens, closes, hasType)

}

.is_valid_snakemake_digraph <- function(x, snake_warn = TRUE){

  # The minimal requirements are a digraph & at least one edge
  is_digraph <- grepl("digraph", x[[1]])
  has_edges <- any(grepl("->", x))
  if (!grepl("snakemake", x[[1]]) & snake_warn) warning(
    "Graph not generated by snakemake. Unexpected structures may be present"
  )
  all(.is_dot(x), is_digraph, has_edges)

}
steveped/spBioUtils documentation built on Sept. 25, 2021, 7:22 p.m.