rguides

Reference

String Functions

String handling and regex helpers.

  1. endsWith()

    Use `endsWith()` in R to test if strings end with a suffix. Returns a logical vector. Useful for filtering files by extension or validating paths.

  2. format()

    Format R objects for pretty printing, controlling decimal places and alignment. The function formats R objects for pretty printing.

  3. formatC()

    Use `formatC()` in R for C-style numeric formatting with width, digits, and flag control. Formats numbers using C format specifications for fixed-width output.

  4. grep()

    Use `grep()` in R to search for pattern matches in character strings, returning indices or values. Supports regex, fixed-string, and case-insensitive matching.

  5. grepl()

    Use `grepl()` in R to search for pattern matches and return a logical vector. Supports regex, fixed-string, and case-insensitive matching for filtering.

  6. gsub()

    Use `gsub()` in R to replace all occurrences of a pattern in strings using regex or fixed matching. Supports backreferences and case-insensitive search.

  7. nchar()

    nchar() returns the length of a string in characters, bytes, or width units for display, essential for validation and text processing in R.

  8. startsWith()

    startsWith() checks if each element of a character vector begins with a specified prefix in R, returning a logical vector for filtering and validation.

  9. strsplit()

    strsplit() splits a character vector into substrings by finding matches of a delimiter pattern, returning a list of split components for each input element.

  10. sub()

    sub() replaces only the first occurrence of a pattern in each string element using regex or fixed matching, distinct from gsub()'s global replacement.

  11. substring()

    substring() extracts or replaces substrings in a character vector by position with vectorized start and stop arguments for flexible indexing.

  12. tolower()

    tolower() converts character vectors to lowercase in R, essential for case-normalization when comparing strings and cleaning text data.

  13. toupper()

    toupper() converts character vectors to uppercase in R, essential for case-normalization when comparing strings and standardizing text data.

  14. trimws()

    trimws() removes leading and trailing whitespace from character strings in base R, essential for cleaning user input and text data before processing.