checkCoercion.RdThis might be named "coercesSafely" or such. If values cannot be coerced into class specified, then values must be incorrect.
checkCoercion(value, targetclass, na.strings = c("\\.", "", "\\s+", "N/A"))either TRUE, or a vector of values which are not successfully coerced
x1 <- c("TRUE", "FALSE", FALSE, TRUE, NA, ".", "N/A", " ", "")
checkCoercion(x1, "logical")
#> [1] TRUE
x1 <- c(x1, "TRUE.FALSE", "Has a space")
## Should fail:
checkCoercion(x1, "logical")
#> checkValue: fails coercion of x1 as logical
#> [1] "TRUE.FALSE" "Has a space"
x2 <- c(4, 5, 6, 9.2, ".", " ")
## Should fail
checkCoercion(x2, "logical")
#> checkValue: fails coercion of x2 as logical
#> [1] "4" "5" "6" "9.2"
x3 <- factor(c("bob", "emily", "bob", "jane", "N/A", " ", NA, "NA"))
checkCoercion(x3, "ordered")
#> [1] TRUE
checkCoercion(x3, "integer")
#> [1] TRUE
## Should fail:
checkCoercion(x3, "logical")
#> checkValue: fails coercion of x3 as logical
#> [1] bob emily bob jane NA
#> Levels: N/A NA bob emily jane