As we have added more textstat functions, and as we redesign the textstat_simil() and textstat_dist(), we've introduced some inconsistencies in the output object types. It's time to think this through and consider some adjustments.
Differences:
- most functions return a data.frame that has the margin name as the id column (e.g.
document or feature), but others such as textstat_entropy return a named numeric vector.
- some functions change the id column depending on the value of the
margin function.
- some functions return multiple statistic names (e.g.
textstat_readability()) while others (e.g. textstat_keyness()) return only one, even though it has a different column name.
- the new
textstat_simil() returns just similarity as the statistic column name, regardless of the value of the measure. Other functions return the name of the measure/method as the statistic.
- the name of the measure is
measure for all functions except the simil and dist functions, where it is method.
- In most of the older ones, we classed them as: ,
textstat, data.frame. But we do not have any methods that are common to a textstat class.
| function |
output class name |
object base |
margin? |
id column(s) |
stat column |
textstat_simil |
textstat_simil |
data.frame |
Y |
feature/document[1,2] |
similarity, regardless of method |
textstat_dist |
dist |
dist |
Y |
n/a |
|
textstat_entropy |
n/a |
named numeric |
Y |
n/a, but names are features or documents |
n/a |
textstat_collocations |
collocations, textstat |
data.frame |
N |
collocation |
lambda, z |
textstat_frequency |
frequency, textstat |
data.frame |
N |
feature |
frequency, rank |
textstat_keyness |
keyness, textstat |
data.frame |
N |
feature |
(single) name of measure |
textstat_lexdiv |
lexdiv, textstat |
data.frame |
N |
document |
(multiple) name of measure |
textstat_readability |
readability, textstat |
data.frame |
N |
document |
(multiple) name of measure |
Proposals:
- All textstat functions should return a data.frame.
- The id column should be one of: feature, document, collocation, with the pairwise simil and dist functions returning feature1, feature2 or document1, document2.
- We rename
method in textstat_simil/dist() to measure, so that all functions use this argument name.
- We return the statistic as the name of the measure, when multiple options exist.
- We allow multiple columns to be returned, by passing multiple values to
measure.
- We class the returned data.frames as
c("textstat_name", "textstat", "data.frame"). This allows us to class the return from textstat_dist for instance without colliding with the class name of the stats::dist() return. This is also consistent with what we return from the textmodel functions.
As we have added more textstat functions, and as we redesign the
textstat_simil()andtextstat_dist(), we've introduced some inconsistencies in the output object types. It's time to think this through and consider some adjustments.Differences:
documentorfeature), but others such astextstat_entropyreturn a named numeric vector.marginfunction.textstat_readability()) while others (e.g.textstat_keyness()) return only one, even though it has a different column name.textstat_simil()returns justsimilarityas the statistic column name, regardless of the value of the measure. Other functions return the name of the measure/method as the statistic.measurefor all functions except the simil and dist functions, where it ismethod.textstat,data.frame. But we do not have any methods that are common to atextstatclass.margin?textstat_similmethodtextstat_disttextstat_entropytextstat_collocationstextstat_frequencytextstat_keynessmeasuretextstat_lexdivmeasuretextstat_readabilitymeasureProposals:
methodintextstat_simil/dist()tomeasure, so that all functions use this argument name.measure.c("textstat_name", "textstat", "data.frame"). This allows us to class the return fromtextstat_distfor instance without colliding with the class name of thestats::dist()return. This is also consistent with what we return from thetextmodelfunctions.