R/utils.R

Defines functions assert_for_int stop2

################################################################################

OPS <- setNames(c("multiply", "add", "substract", "divide"), 
                c('*', '+', '-', '/'))

################################################################################

stop2 <- function(...) stop(sprintf(...), call. = FALSE)

################################################################################

assert_for_int <- function(x, val, op) {
  
  if (typeof(x) == "integer") {
    
    if (op == '/') {
      stop2("Division is not allowed for type integer.")
    } else {
      if (any(trunc(val) != val)) 
        stop2("'%s' should have integer values only.", deparse(substitute(val)))
    }
    
  }
}

################################################################################

Try the inplace package in your browser

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

inplace documentation built on Aug. 24, 2020, 5:08 p.m.