R/board.R

Defines functions board

Documented in board

#' board
#'
#' @param mat a valid matrix
#' @param n side length if no mat is provided
#' @param p proportion of filled cells if no mat is provided
#'
#' @return a board class object of the matrix or n/p values that inherits from matrix
#' @export
#' @import testthat
#' @examples board()
board = function(mat = NULL, n = 5, p = 0.25){
  if (!is.null(mat)) {
    is_valid(mat)
    object = mat
    attr(object, "n") = nrow(mat)
    attr(object, "p") = sum(mat == 0)/nrow(mat)^2
  } else {
    object = generate_board_mat(n,p)
    attr(object, "n") = n
    attr(object, "p") = p
  }
  class(object) = c("board", "matrix")
  return(object)

}
Achowdh1/percolate documentation built on Oct. 30, 2019, 4:09 a.m.