Fold or unfold a string on the expansion operator.

string_unfold(x)

string_fold(x, n = 3)

Arguments

x

character string, should be valid notes or note info such as beats.

n

integer, minimum number of consecutive repeated values to warrant folding, defaults to 3.

Value

character

Details

These function work on arbitrary stings. They do not perform a noteworthy check. This allows them to work for info strings as well. Make sure your strings are properly formatted. string_fold() always collapses the output string as space-delimited.

Examples

time <- "8*3 16 4.. 16 16 2 2 4. 8 4 4 8*4 1"
x <- string_unfold(time)
x
#> [1] "8 8 8 16 4.. 16 16 2 2 4. 8 4 4 8 8 8 8 1"
string_fold(x) == time
#> [1] TRUE

notes <- "a, b, c d e f g# a r ac'e' a c' e' c' r r r a"
x <- string_fold(notes)
x
#> [1] "a, b, c d e f g# a r ac'e' a c' e' c' r*3 a"
string_unfold(x) == notes
#> [1] TRUE