Description Usage Arguments Value Examples
View source: R/check_and_rep.R
Checks that a vector has a given lengths, if x is null or NA, the default is repeated a given amount
1 | check_and_rep(x, req_size, default = "white", name = "x")
|
x |
a vector, a matrix, or a data.frame |
req_size |
a required size of x (a single value for a vector or a vector of 2 values) |
default |
default values if x is NULL/NA |
name |
a name of x (for the error message only) |
a vector of size req_size or a matrix (if req_size has length 2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # vector
check_and_rep(NA, 3, "red")
check_and_rep("green", 3, "red")
## Not run:
# produces an error
check_and_rep(c("red", "green"), 3, "red")
# change the name of x
check_and_rep(c("red", "green"), 3, "red", "fancy_vector")
## End(Not run)
check_and_rep(c("red", "green", "blue"), 3, "red")
# Matrix
check_and_rep("green", c(2, 3), "white")
x <- matrix(c("red", "green", "blue", "yellow"), 2, 2)
check_and_rep(x, c(2, 2), "white")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.