Learn R Programming

Xmisc (version 0.2.1)

valid.arg.index: Check validity of an index

Description

Check validity of an index of a list object.

Usage

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.

Examples

Run this code
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

Run the code above in your browser using DataLab