Skip to content

CarwilB/regexcite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

regexcite

The goal of regexcite is to make using regular expressions a bit easier.

Installation

You can install the development version of regexcite from GitHub with:

# install.packages("devtools")
devtools::install_github("CarwilB/regexcite")

Usage

A fairly common task when dealing with strings is the need to split a single string into many parts. This is what base::strplit() and stringr::str_split() do.

(x <- "alfa,bravo,charlie,delta")
#> [1] "alfa,bravo,charlie,delta"
strsplit(x, split = ",")
#> [[1]]
#> [1] "alfa"    "bravo"   "charlie" "delta"
stringr::str_split(x, pattern = ",")
#> [[1]]
#> [1] "alfa"    "bravo"   "charlie" "delta"

Notice how the return value is a list of length one, where the first element holds the character vector of parts. Often the shape of this output is inconvenient, i.e. we want the un-listed version.

That’s exactly what regexcite::str_split_one() does.

library(regexcite)

str_split_one(x, pattern = ",")
#> [1] "alfa"    "bravo"   "charlie" "delta"

Use str_split_one() when the input is known to be a single string. For safety, it will error if its input has length greater than one.

The function str_split inherits the options of str_split. For example…

library(regexcite)

str_split_one("a,b,c", ",", n = 2)
#> [1] "a"   "b,c"

str_split_one("a.b", stringr::fixed("."))
#> [1] "a" "b"

You’ll still need to render README.Rmd regularly, to keep README.md up-to-date. devtools::build_readme() is handy for this.

About

Improve regular expression handling

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages