expand_braces() performs brace expansions on strings. str_expand_braces() is an alternate that returns a list of character vectors. Made popular by Unix shells, brace expansion allows users to concisely generate certain character vectors by taking a single string and (recursively) expanding the comma-separated lists and double-period-separated integer and character sequences enclosed within braces in that string. The double-period-separated numeric integer expansion also supports padding the resulting numbers with zeros.

expand_braces(string, engine = getOption("bracer.engine", NULL))

str_expand_braces(string, engine = getOption("bracer.engine", NULL))

Arguments

string

input character vector

engine

If 'r' use a pure R parser. If 'v8' use the 'braces' Javascript parser via the suggested V8 package. If NULL use 'v8' if 'V8' package detected else use 'r'; in either case send a message() about the choice unless getOption(bracer.engine.inform') is FALSE.

Value

expand_braces() returns a character vector while str_expand_braces() returns a list of character vectors.

Examples

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