File: allocArray.R

package info (click to toggle)
r-cran-matrixstats 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,104 kB
  • sloc: ansic: 7,300; sh: 11; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library("matrixStats")

allocArray_R <- function(nrow, ncol, value = NA) {
  array(data = value, dim = dim)
}

values <- list(
  -1L, 0L, +1L, NA_integer_, .Machine$integer.max,
  -1, 0, +1, NA_real_, NaN, -Inf, +Inf,
  .Machine$double.xmin, .Machine$double.xmax,
  .Machine$double.eps, .Machine$double.neg.eps,
  FALSE, TRUE, NA
)

dim <- c(2L, 4L, 3L)
for (value in values) {
  x0 <- allocArray_R(dim, value = value)
  x <- allocArray(dim, value = value)
  if (!identical(x, x0)) {
    str(list(dim = dim, value = value, x = x, x0 = x0))
    stopifnot(identical(x, x0))
  }
}