Modified version of base::seq_len()
that returns a zero-length integer in case of a zero-length input instead of throwing an error.
Examples
pal::safe_seq_len(5)
#> [1] 1 2 3 4 5
# this function simply returns a zero-length integer for zero-length inputs...
pal::safe_seq_len(NULL)
#> integer(0)
pal::safe_seq_len(integer())
#> integer(0)
# ...while `seq_len()` throws an error
try(seq_len(NULL))
#> Warning: first element used of 'length.out' argument
#> Error in seq_len(NULL) :
#> argument must be coercible to non-negative integer
try(seq_len(integer()))
#> Warning: first element used of 'length.out' argument
#> Error in seq_len(integer()) :
#> argument must be coercible to non-negative integer