Checking if the length of the different elements of a list corresponds to what one expects.
checkLength(listObjects, lengthObjects)
List of vectors, of irrespective data type.
Numeric vector, either of the same length as the 'listObjects' argument, or of length 1, but in the latter case, it will be tested whether or not the length of every element of the 'listObjects' argument equal this one value.
No value is returned if all vectors correspond to the length against which it is tested. An error message is thrown when the length does not corresponds for at least one element of the list.
# NOT RUN {
arg1 <- 'something'
checkLength(list(arg1), 1)
checkLength(list('somethingElse', TRUE), 1)
checkLength(list('somethingElse', TRUE), c(1, 1))
arg2 <- 2:5
checkLength(list(arg1, arg2), c(1, 4))
# }
# NOT RUN {
checkLength(list(arg1, arg2), 1)
# }
Run the code above in your browser using DataLab