valid.arg.index: Check validity of an index

Description Usage Arguments Value Author(s) Examples

Description

Check validity of an index of a list object.

Usage

1
valid.arg.index(obj, x, safe = TRUE)

Arguments

obj

list

x

index or name of an element

safe

whether safe if an index is higher than the one of any named element

Value

numeric, the index. Return numeric(0) if the name or the index does not exist or when the index is invalid. If safe is FALSE, any index is valid; if safe is TRUE, an index is invalid when the indexed element is positionally after another named element.

Author(s)

Xiaobei Zhao

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ll <- list(11,12,13,a=14,b=15,16,17,c=18,19)
valid.arg.index(ll,-1) # non-existing index
valid.arg.index(ll,0)  # non-existing index
valid.arg.index(ll,1)  # valid index
valid.arg.index(ll,2)  # valid index
valid.arg.index(ll,5)  # invalid index
valid.arg.index(ll,10) # non-existing index
valid.arg.index(ll,"a")# valid name
valid.arg.index(ll,"e")# non-existing name
valid.arg.index(ll,5,safe=FALSE) # still return the index

Xmisc documentation built on May 2, 2019, 8:23 a.m.