locate: Locate all occurrences of a vector (needle) within another...

Description Usage Arguments Details Value

View source: R/locate.R

Description

This will return all starting locations of the needle found within the haystack - even overlapping ones.

Usage

1
2
3
4
5
locate(needle, haystack, alignment = NA_integer_)

cached_locate(needle, haystack, alignment = NA_integer_)

locate_next(needle, haystack, start = 1L, alignment = NA)

Arguments

needle

vector of values

haystack

vector of values

alignment

search must start at a multiple of this index location (+1). Useful for byte-aligned searches of bit vectors i.e. alignment=8. Default: NA (no alignment).

start

lowest index to accept

Details

The routine is pretty relaxed about types so you can search for an integer vector within a character vector if you so choose.

Supported types:

locate is the core location function. There is no cacheing, so identical searches are started from scratch each time.

cached_locate is a memoised version of locate. Because calling locate can be quite an expensive operation, searches for a given sequence in a haystack are cached to save time on subsequent calls.

locate_next gives the first index on, or after, the given start index.

Adapted from code originally written by carroll_jono - https://twitter.com/carroll_jono

Value

Indices of the start of all occurrences of needle in haystack, or NA if no matches found.


coolbutuseless/minilocate documentation built on May 20, 2019, 9:41 a.m.