check_num_int: Check variable class for numeric / integer

Description Usage Arguments Value Examples

View source: R/check_num_int.R

Description

Match variable class with one of numeric or integer and abort by 'abort' otherwise.

Usage

1
check_num_int(var, n = NULL, allowNULL = FALSE)

Arguments

var

variable to check

n

numeric to also check length var

allowNULL

allow to pass check if var NULL? FALSE by default

Value

silent if check is passed, rlang error otherwise

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  id <- 2
  check_num_int(id)

  id <- 2L
  check_num_int(id)
  
  # check variable type and length
  check_num_int(id, n = 1)

  # pass check if variable NULL
  id <- NULL
  check_num_int(id, allowNULL = TRUE)

  ## Not run: 
    # generates error
    id <- "2"
    check_num_int(id)
  
## End(Not run)

thfuchs/testr documentation built on Jan. 22, 2021, 2:35 p.m.