diff --git a/R/cell.R b/R/cell.R new file mode 100644 index 0000000..4bcf072 --- /dev/null +++ b/R/cell.R @@ -0,0 +1,14 @@ +#' @title Cell array +#' @description Creates an array of zeros +#' @param n a the first dimension (or both, if sz is not passed) +#' @param sz the second dimension (or 1st and 2nd, if not passed) +#' @return An array of zeroes with the dimensions passed on call +cell <- function(n, sz = c(n, n), ...) { + if (length(sz) == 1 & missing(...)) { + return(array(dim = c(n, sz))) + } else if (length(sz) == 2) { + return(array(dim = sz)) + } else { + return(array(dim = c(n, sz, ...))) + } +} \ No newline at end of file diff --git a/man/cell.Rd b/man/cell.Rd new file mode 100644 index 0000000..428527c --- /dev/null +++ b/man/cell.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cell.R +\name{cell} +\alias{cell} +\title{Cell array} +\usage{ +cell(n, sz = c(n, n), ...) +} +\arguments{ +\item{n}{a the first dimension (or both, if sz is not passed)} + +\item{sz}{the second dimension (or 1st and 2nd, if not passed)} +} +\value{ +An array of zeroes with the dimensions passed on call +} +\description{ +Creates an array of zeros +} diff --git a/tests/testthat/test-convertedBaseFunctions.R b/tests/testthat/test-convertedBaseFunctions.R index 63fa4bb..ca945c3 100644 --- a/tests/testthat/test-convertedBaseFunctions.R +++ b/tests/testthat/test-convertedBaseFunctions.R @@ -161,3 +161,11 @@ test_that("sortrows works as expected", { expect_equal(sortrows(mx, 2), matrix(c(2, 3, 1, 2, 0, 1, pi, 10), 4)) expect_equal(sortrows(mx, 1:2), mx[order(mx[, 1], mx[, 2]), ]) }) + +test_that("cell works as expected", { + expect_equal(cell(0), array(dim = c(0, 0))) + expect_equal(cell(1), array(dim = c(1, 1))) + expect_equal(cell(2), array(dim = c(2, 2))) + expect_equal(cell(3, 4), array(dim = c(3, 4))) + expect_equal(cell(5, 7, 6), array(dim = c(5, 7, 6))) +}) \ No newline at end of file