startsWith: Determine if a character string "starts with" with the...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/startsWith.R

Description

Determine if a character string "starts with" with the specified characters.

Usage

1
startsWith(str, pattern, trim=FALSE, ignore.case=FALSE)

Arguments

str

character vector to test

pattern

characters to check for

trim

Logical flag indicating whether leading whitespace should be removed from str before testing for a match.

ignore.case

Logical flag indicating whether case should be ignored when testing for a match.

Details

This function returns TRUE for each element of the vector str where pattern occurs at the beginning of the string. If trim is TRUE, leading whitespace is removed from the elements of str before the test is performed. If ignore.case is TRUE, character case is ignored.

Value

Boolean vector of the same length as str.

Author(s)

Gregory R. Warnes [email protected]

See Also

substr, trim

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## simplest example:
startsWith( 'Testing', 'Test')

## vector examples
s <- c('Testing', ' Testing', 'testing', 'Texting')
names(s) <- s

startsWith(s, 'Test')                   # ' Testing', 'testing', and 'Texting' do not match
startsWith(s, 'Test', trim=TRUE)        # Now ' Testing' matches
startsWith(s, 'Test', ignore.case=TRUE) # Now 'testing' matches

Example output

sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

The following object is masked from 'package:stats':

    nobs

The following object is masked from 'package:utils':

    object.size

The following object is masked from 'package:base':

    startsWith

[1] TRUE
[1]  TRUE FALSE FALSE FALSE
[1]  TRUE  TRUE FALSE FALSE
[1]  TRUE FALSE  TRUE FALSE

gdata documentation built on June 6, 2017, 5:04 p.m.