string_chomp: Remove (empty) characters from a string as inspired by Ruby

View source: R/string_chomp.R

string_chompR Documentation

Remove (empty) characters from a string as inspired by Ruby

Description

Remove (empty) characters from a string as inspired by Ruby.

Usage

string_chomp(s)
string_chop(s)
string_trim(s, which, whitespace)
string_cut(s, which)

Arguments

s

A string (character) vector.

which

Denotes how to trim/cut a vector (both, left only, or right only).

whitespace

Denotes which whitespace characters to remove.

Details

As inspired by Ruby, string_chomp() removes all whitespace characters in a string.

The function string_chop() removes the last character from a string.

The function string_trim() acts the same as trimws but its source code is more readable (in my opinion!).

string_cut() removes characters from either the left, right, or both ends of a string.

The synonym pattern of these functions are s_*() and *() (replace asterisks with upper, chomp, chop, and trim. s_cut() is the only synonym for string_cut()).

Value

Character vector.

See Also

https://github.com/robertschnitman/stringops

Examples

string_chomp(rownames(mtcars))
string_chop(rownames(mtcars))
string_trim("   s   ")
string_cut("cut this please", which = 'both')


robertschnitman/stringops documentation built on Aug. 15, 2022, 3:46 p.m.