R/internal.R

Defines functions isMinusInfinity isPlusInfinity Columns makePermutation inversePermutation integerRange isPositiveInteger

isPositiveInteger <- function(x) {
  is.numeric(x) && length(x) == 1L && !is.na(x) && floor(x) == x && x > 0
}

integerRange <- function(start, stop) {
  if(stop >= start) {
    start:stop
  } else {
    integer(0L)
  }
}

inversePermutation <- function(p) {
  p[p] <- seq_along(p)
  p
}

makePermutation <- function(n, var) {
  var <- as.integer(var)
  c(integerRange(1L, var-1L), integerRange(var+1L, n), var)
}

Columns <- function(M) {
  apply(M, 2L, identity, simplify = FALSE)
}

isPlusInfinity <- function(x) {
  is.infinite(x) && x > 0
}

isMinusInfinity <- function(x) {
  is.infinite(x) && x < 0
}

Try the resultant package in your browser

Any scripts or data that you put into this service are public.

resultant documentation built on Sept. 11, 2024, 8:01 p.m.