Helper functions for concatenating musical phrases and raw strings together as well as repetition.


pn(x, n = 1)



character, phrase or non-phrase string.


character, phrase or non-phrase string.


integer, number of repetitions.


phrase on non-phrase character string, noteworthy string if applicable.


Note: When working with special tabr classes, you can simply use generics like c() and rep() as many custom methods exist for these classes. The additional respective helper functions, pc() and pn(), are more specifically for phrase objects and when you are still working with character strings, yet to be converted to a phrase object (numbers not yet in string form are allowed). See examples.

The functions pc() and pn() are based on base functions paste() and rep(), respectively, but are tailored for efficiency in creating musical phrases.

These functions respect and retain the phrase class when applied to phrases. They are aggressive for phrases and secondarily for noteworthy strings. Combining a phrase with a non-phrase string will assume compatibility and result in a new phrase object. If no phrase objects are present, the presence of any noteworthy string will in turn attempt to force conversion of all strings to noteworthy strings. The aggressiveness provides convenience, but is counter to expected coercion rules. It is up to the user to ensure all inputs can be forced into the more specific child class.

This is especially useful for repeated instances. This function applies to general slur notation as well. Multiple input formats are allowed. Total number of note durations must be even because all slurs require start and stop points.


pc(8, "16-", "8^")
#> [1] "8 16- 8^"
pn(1, 2)
#> [1] "1 1"
x <- phrase("c ec'g' ec'g'", "4 4 2", "5 432 432")
y <- phrase("a", 1, 5)
pc(x, y)
#> <Musical phrase>
#> <c\5>4 <e\4 c'\3 g'\2>4 <e\4 c'\3 g'\2>2 <a\5>1
pc(x, pn(y, 2))
#> <Musical phrase>
#> <c\5>4 <e\4 c'\3 g'\2>4 <e\4 c'\3 g'\2>2 <a\5>1 <a\5>1
pc(x, "r1") # add a simple rest instance
#> <Musical phrase>
#> <c\5>4 <e\4 c'\3 g'\2>4 <e\4 c'\3 g'\2>2 r1
class(pc(x, y))
#> [1] "phrase"    "character"
class(pn(y, 2))
#> [1] "phrase"    "character"
class(pc(x, "r1"))
#> [1] "phrase"    "character"
class(pn("r1", 2))
#> [1] "character"
class(pc("r1", "r4"))
#> [1] "character"