#' 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.