CheckInput | R Documentation |
An input vector (of length one unless okSeveral
is TRUE
) is checked.
CheckInput(
x,
alt = NULL,
min = NULL,
max = NULL,
type = "character",
data = NULL,
okSeveral = FALSE,
okNULL = FALSE,
okNA = FALSE,
okDuplicates = is.null(alt) & !(type %in% c("varName", "varNr", "varNrName"))
)
check_input(
x,
alt = NULL,
min = NULL,
max = NULL,
type = "character",
data = NULL,
okSeveral = FALSE,
okNULL = FALSE,
okNA = FALSE,
okDuplicates = is.null(alt) & !(type %in% c("varName", "varNr", "varNrName"))
)
x |
Input vector to be checked |
alt |
|
min |
|
max |
|
type |
One of: |
data |
A data frame or matrix. When above type is |
okSeveral |
When |
okNULL |
When |
okNA |
When |
okDuplicates |
When |
x
is checked according to the other input parameters.
When x
is wrong an error is produced with appropriate text.
The function was originally created in 2016 and has been included in internal packages at Statistics Norway (SSB). Due to its widespread use, it was beneficial to include it in this CRAN package.
check_input
and CheckInput
are identical
Øyvind Langsrud
a <- c("no", "yes")
b <- c(3.14, 4, 5)
z <- data.frame(A = a, B = b[1:2], C = TRUE)
# Lines causing error are embedded in 'try'
try(CheckInput(a, type = "character"))
CheckInput(a, type = "character", alt = c("no", "yes", "dontknow"), okSeveral = TRUE)
try(CheckInput("yesno", type = "character", alt = c("no", "yes", "dontknow")))
CheckInput(a[1], type = "character", alt = c("no", "yes", "dontknow"))
try(CheckInput(b, type = "integer", max = 100, okSeveral = TRUE))
try(CheckInput(b, type = "numeric", min = 4, okSeveral = TRUE))
CheckInput(b, type = "numeric", max = 100, okSeveral = TRUE)
try(CheckInput(b, type = "numeric", alt = 1:10, okSeveral = TRUE))
CheckInput(b[2], type = "numeric", alt = 1:10)
try(CheckInput("TRUE", type = "logical"))
CheckInput(TRUE, type = "logical")
try(CheckInput("A", type = "varName"))
CheckInput("A", type = "varName", data = z)
CheckInput(c("A", "B"), type = "varNrName", data = z, okSeveral = TRUE)
try(CheckInput("ABC", type = "varNrName", data = z))
try(CheckInput(5, type = "varNrName", data = z))
CheckInput(3, type = "varNr", data = z)
CheckInput(2:3, type = "varNr", data = z, okSeveral = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.