safe_dim tries to get dimensions from dim and falls back on length if dim returns NULL

safe_dim(x)

Arguments

x

the object to get dimensions from