bracer

CRAN Status Badge Travis-CI Build Status AppVeyor Build Status Coverage Status Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.

bracer provides support for performing brace expansions on strings in R.

Examples

library("bracer")
expand_braces("Foo{A..F}")
## [1] "FooA" "FooB" "FooC" "FooD" "FooE" "FooF"
expand_braces("Foo{01..10}")
##  [1] "Foo01" "Foo02" "Foo03" "Foo04" "Foo05" "Foo06" "Foo07" "Foo08"
##  [9] "Foo09" "Foo10"
expand_braces("Foo{A..E..2}{1..5..2}")
## [1] "FooA1" "FooA3" "FooA5" "FooC1" "FooC3" "FooC5" "FooE1" "FooE3" "FooE5"
expand_braces("Foo{-01..1}")
## [1] "Foo-01" "Foo000" "Foo001"
expand_braces("Foo{{d..d},{bar,biz}}.{py,bash}")
## [1] "Food.py"     "Food.bash"   "Foobar.py"   "Foobar.bash" "Foobiz.py"  
## [6] "Foobiz.bash"

expand_braces is vectorized and returns one big character vector of all the brace expansions. str_expand_braces is an alternative that returns a list of character vectors.

expand_braces(c("Foo{A..F}", "Bar.{py,bash}", "{{Biz}}"))
## [1] "FooA"     "FooB"     "FooC"     "FooD"     "FooE"     "FooF"    
## [7] "Bar.py"   "Bar.bash" "{{Biz}}"
str_expand_braces(c("Foo{A..F}", "Bar.{py,bash}", "{{Biz}}"))
## [[1]]
## [1] "FooA" "FooB" "FooC" "FooD" "FooE" "FooF"
## 
## [[2]]
## [1] "Bar.py"   "Bar.bash"
## 
## [[3]]
## [1] "{{Biz}}"

glob is a wrapper around Sys.glob that uses expand_braces to support both brace and wildcard expansion on file paths.

glob("R/*.{R,r,S,s}")
## [1] "R/expand.R" "R/glob.R"

Installation

To install the release version on CRAN use the following command in R:

install.packages("bracer")

To install the developmental version use the following command in R:

remotes::install_github("trevorld/bracer")

Caveats

bracer currently does not properly support the “correct” (Bash-style) brace expansion under several edge conditions such as:

  1. Unbalanced braces e.g. {{a,d} (but you could use an escaped brace instead \\{{a,d})
  2. Using surrounding quotes to escape terms e.g. {'a,b','c'} (but you could use an escaped comma instead {a\\,b,c})
  3. Escaped braces within comma-separated lists e.g. {a,b\\}c,d}
  4. (Non-escaping) backslashes before braces e.g. {a,\\\\{a,b}c}
  5. Sequences from letters to non-letter ASCII characters e.g. X{a..#}X