Translated cell(), added tests
This commit is contained in:
parent
862a91febc
commit
31aeb99257
3 changed files with 41 additions and 0 deletions
14
R/cell.R
Normal file
14
R/cell.R
Normal file
|
|
@ -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, ...)))
|
||||||
|
}
|
||||||
|
}
|
||||||
19
man/cell.Rd
Normal file
19
man/cell.Rd
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -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, 2), matrix(c(2, 3, 1, 2, 0, 1, pi, 10), 4))
|
||||||
expect_equal(sortrows(mx, 1:2), mx[order(mx[, 1], mx[, 2]), ])
|
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)))
|
||||||
|
})
|
||||||
Loading…
Add table
Reference in a new issue