Strings: Head and Tail functions for Strings.

StringsR Documentation

Head and Tail functions for Strings.

Description

C++ implemetations of convenience functions for strings. All functions but strTake operate with O(1) memory.

strHead returns the first character of a string

strHeadLower returns the first character of a string coerced to lower case

strTail returns all but the first character of a string

strTake returns the first n characters of a string

strDrop returns all but the first n characters of a string

Usage

strHead(s)
strHeadLower(s)
strTail(s)
strTake(s, n)
strDrop(s, n)

Arguments

s

a string object

n

the number of characters to take or drop

Details

A few convenient list operations, tailored to 8-bit-character strings.

Value

A character vector.

Note

While originally also implemented for performance reasons, the built-in substr function is usually faster due to the Call-overhead. At least for R 3.x onward the built-in functions should be preferred when performance is an issue. See the vignette for details.

Examples

strHead("Gnu")
strHeadLower("Gnu")
strTail("Gnu")
strTake("Gnus and Gnats",3)
strDrop("Gnus and Gnats",9)

wamserma/R-wmisc documentation built on March 19, 2023, 3:06 a.m.