Skip to contents

The function tags text according to keywords or quanteda dictionaries.

Usage

tagText(text, 
        title="Document Title", 
        keywords=NULL,
        palette=c("#DD8D29","#E2D200","#46ACC8","#E58601","#B40F20"),
        bright=130, 
        tooltip=TRUE, 
        html.return=FALSE, 
        viewer=TRUE, 
        url.return=FALSE, 
        margin=50, 
        font.size=12)

Arguments

text

Text to be used for tagging or highlighting.

title

The title or header of the tagged document. The default is "Document Title".

keywords

The keywords or the dictionary to be used to highlight or tag the submitted text. The default is NULL.

palette

The color palette for the text to be highlighted.

bright

Luminosity threshold to separate bright to dark colors. This parameter will be passed to the colBright function. The default is 130.

tooltip

Logical. Indicates whether the final document should include a tooltip containing the dictionary categories or not. The default is TRUE.

html.return

Logical. When TRUE, returns the html code generated by the function to be stored and saved into a file. The default is FALSE.

viewer

Logical. When TRUE, show the results on RStudio Viewer panel. When FALSE, opens the file on the default browser. The default is TRUE.

url.return

Logical. When TRUE, returns the location of the temporary html file stored in the computer. The default is FALSE.

margin

Defines the size of the html file margins in pixels. The default is 50.

font.size

Establishes the font size for the text to be represented. The default is 12.

Details

The function tagText finds and highlights words and expressions in a given text. It was designed to help qualitative researchers to locate themes and issues in narrative texts and documents. Therefore, it is meant to be an exploratory tool for qualitative analysis and a step in a broader coding process of text.

Value

There are two possible values to be returned.

The first is the html code generated by the function. This option is particularly interesting in the case users plan to save the results into a file. It becomes effective only when html.return=TRUE.

The second is the location of the temporary file generated by the function. It becomes effective when html.return=TRUE.

Examples

if (FALSE) {
# Create a text variable as example
tx <- c("Political regimes can be classified 
as liberal democracies, electoral democracies, 
electoral autocracies, and full autocracies.")

# Find words starting with "democ" in the text
tagText(tx, keywords="democr")


# Creates a dictionary to classify regimes
regimes <- quanteda::dictionary(list(
                  Democracy=c("democ"),
                  Autocracy=c("autoc")
                      ))

# Change the default colors
tagText(tx, keywords=regimes)
}