Learn R Programming

sentometrics (version 0.2)

ctr_merge: Set up control for merging sentiment measures

Description

Sets up control object for the optional merging (additional aggregation) of sentiment measures as done by merge_measures.

Usage

ctr_merge(sentomeasures, features = NA, lexicons = NA, time = NA,
  do.keep = FALSE)

Arguments

sentomeasures

a sentomeasures object created using sento_measures. This is necessary to check whether the other input arguments make sense.

features

a list with unique features to merge at given name, e.g., list(feat12 = c("feat1", "feat2")). See sentomeasures$features for the exact names to use. Use NA to apply no merging across this dimension.

lexicons

a list with unique lexicons to merge at given name, e.g., list(lex12 = c("lex1", "lex2")). See sentomeasures$lexicons for the exact names to use. Use NA to apply no merging across this dimension.

time

a list with unique time weighting schemes to merge at given name, e.g., list(tw12 = c("tw1", "tw2")). See sentomeasures$time for the exact names to use. Use NA to apply no merging across this dimension.

do.keep

a logical indicating if the original sentiment measures should be kept (i.e., the merged sentiment measures will be added to the current sentiment measures as additional indices if do.keep = TRUE).

Value

A list encapsulating the control parameters.

See Also

merge_measures

Examples

Run this code
# NOT RUN {
data("usnews")
data("lexicons")
data("valence")

# construct a sentomeasures object to start with
corpus <- sento_corpus(corpusdf = usnews)
corpusSample <- quanteda::corpus_sample(corpus, size = 750)
l <- setup_lexicons(lexicons[c("LM_eng", "HENRY_eng")], valence[["valence_eng"]])
ctr <- ctr_agg(howTime = c("equal_weight", "linear"), by = "year", lag = 3)
sentomeasures <- sento_measures(corpusSample, l, ctr)

# set up a correct control function
ctrMerge <- ctr_merge(sentomeasures,
                      time = list(W = c("equal_weight", "linear")),
                      lexicons = list(LEX = c("LM_eng", "HENRY_eng")),
                      features = list(journals = c("wsj", "wapo")),
                      do.keep = TRUE)

# }
# NOT RUN {
# produces an informative error message
ctrMerge <- ctr_merge(sentomeasures,
                      time = list(W = c("equal_weight", "almon1")),
                      lexicons = list(LEX = c("LM_eng", "HENRY_eng")),
                      features = list(journals = c("notInHere", "wapo")))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab