check if array is empty in R
Code snippet on how to check if array is empty in R
is.null(unname(length(myArray)))
This code checks if the array is empty by first returning the length of the array with the length()
function. The unname()
function is then used to strip away any names associated with the array and the output of this is then fed into the is.null()
function to give a logical TRUE/FALSE output. If the array is empty, then length()
will return 0, unname()
will strip away any names and is.null()
will return TRUE. If the array has values, then length()
will return a non-zero value, unname()
will not affect the output and is.null()
will return FALSE.