ifInd_strip_noInd: Strip the not-indexed equivalents of the elements whose names...

Description Usage Arguments Details Value Examples

View source: R/helperMisc.R

Description

An index is implied if a character vector contains the '['. If x contains both 'w' and 'w[1]' as elements, will return only 'w[1]'. Purpose is for avoiding redundancy when an object name can stand as a shortcut for an object and all of its indices. Care is to be taken, though, because if 'w' is length 2, 'w[2]' would be omitted in the above example, even though by specifying 'w' one may have intended to imply 'w[2]'.

Usage

1

Arguments

x

A character vector

Details

This function may behave strangely if x contains the '[' character that does not refer to an index, or is not followed by ']', which together surround regular R-style indexing syntax. See Examples.

Value

If x has positive length, returns a character vector of at least length 1 , but no longer than length(x)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Typical/ intended use
ifInd_strip_noInd(c("theta","w","w[1]"))

# Odd use
# Note that the last element is valid R syntax
# Yet Z is not removed
ifInd_strip_noInd(c("Z", "Z[", "do.call('[', list(Z,1))"))

# However, if normal and odd indexing exists,
# only the standard "Z" is stripped out
ifInd_strip_noInd(c("Z", "Z[1]", "Z[", "do.call('[', list(Z,1))"))

rBatt/trawlDiversity documentation built on Aug. 14, 2021, 1:01 p.m.