rend | R Documentation |
Rend, as in "to rend apart," splits data in separate fields into separate spines or paths.
Under the hood, rend()
essentially runs a specialized call to make the humdrum table
"longer"/"taller," similar to R functions like melt(), gather(), or pivot_longer().
In fact, a humdrumR method for pivot_longer() is defined, which is equivalent to rend()
.
The rend()
function is essentially the inverse of cleave()
.
rend(humdrumR, ..., fieldName = NULL, removeRended = TRUE, rendEmpty = FALSE)
## S3 method for class 'humdrumR'
pivot_longer(data, cols, ...)
humdrumR |
HumdrumR data. Must be a humdrumR data object. |
... |
Which fields to rend? These arguments can be any combination of |
fieldName |
A name for the newly rended field. Defaults to pasting the names of selected fields ( Must be either |
removeRended |
Should rended fields be removed from the output? Defaults to Must be a singleton |
rendEmpty |
Empty spines be rended? Defaults to Must be a singleton |
The rend()
function takes any number of ...
arguments to select fields in the humdrumR
data.
The identified fields are then split into new spines.
If no fields are provided, the data's selected fields are rended.
New spines are generated from existing spines; if we start with spines 1, 2, 3, and rend two fields...
the original spine 1 will be rended into new spines 1 and 2;
the original spine 2 will be rended into new spines 3 and 4;
the original spine 3 will be rended into new spines 5 and 6.
However, by default, spines are only rended if they contain non-null data points
in the target fields.
If for example, the original spine 2 had no non-null data in one of the rended fields,
if would not be rended into two spines.
However, if rendEmpty
is set to TRUE
,
all spines will be rended even if empty (all null data).
Note that, since differnt fields may be different data types, rend()
will generally coerce the result to character
.
When you rend fields, a new field is generated.
The name of the new field is specified by newField
—by default, newField
is NULL
and the names of the rended
fields are simply pasted together.
If removeRended = TRUE
(the default), the original fields are removed from the data.
However, certain fields, like Token
and any structural fields cannot be removed from the data.
Therefore, if you rend these fields, they will not be deleted, even if removeRended = TRUE
.
If you only provide one field name to rend, is automatically take to be Token
.
Thus, rend(humData, 'Solfa')
is equivalent to rend(humData, 'Token', 'Solfa')
.
The complement/opposite of rend()
is cleave()
.
Other Humdrum table reshaping functions:
cleave()
,
collapseHumdrum()
,
expandPaths()
Other Humdrum table pivoting functions:
cleave()
humData <- readHumdrum(humdrumRroot, "HumdrumData/BachChorales/chor00[1-4].krn")
humData |>
mutate(Recip = recip(Token),
Solfa = solfa(Token, simple = TRUE)) -> humData
humData |> rend(c('Recip', 'Solfa'))
humData |> select(c('Recip', 'Solfa')) |> rend()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.