rename_tags: Rename a term_count Object's Term Columns

Description Usage Arguments Value Examples

View source: R/rename_tags.R

Description

Safely rename a term_count object's tag columns and attributes.

Usage

1
rename_tags(x, old, new)

Arguments

x

A term_count object.

old

A vector of the current names.

new

A vector of new names corresponding to the order of old names.

Value

Returns a renamed term_count object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
data(presidential_debates_2012)

discoure_markers <- list(
    response_cries = c("\\boh", "\\bah", "\\baha", "\\bouch", "yuk"),
    back_channels = c("uh[- ]huh", "uhuh", "yeah"),
    summons = "hey",
    justification = "because"
)

(markers <- with(presidential_debates_2012,
    term_count(dialogue, list(person, time), discoure_markers)
))


rename_tags(markers, old = c('summons', 'back_channels'), new = c('s', 'bcs'))
rename_tags(markers, old = c('person'), new = c('people'))
rename_tags(markers, old = c('person', 'back_channels', 'summons'), new = c('people', 'bcs', 's'))
attributes(rename_tags(markers, old = c('back_channels', 'summons'), new = c('bcs', 's')))

#' ## Token Counts
token_list2 <- list(
    list(
        noun__person = c('sam', 'i')
    ),
    list(
        noun__place = c('here', 'house'),
        noun__thing = c('boat', 'fox', 'rain', 'mouse', 'box', 'eggs', 'ham')
    ),
    list(
        feeling__no_like = c('not like'),
        noun__thing = c('train', 'goat'),
        other__other = c('in')
    ),
    list(
        other__other = 'i'
    )
)


x <- token_count(sam_i_am, grouping.var = TRUE, token.list = token_list2)

## Not run: 
## Strips meta tags
x %>%
    rename_tags(
        c('noun__person', 'noun__place', 'feeling__no_like'), 
        c('human', 'ten_20', 'dislike')
    )

## End(Not run)

trinker/termco documentation built on Jan. 7, 2022, 3:32 a.m.