Description Usage Arguments Details Value Examples
This is the main function for adding colors, onclick effects, etc. to tokens, for which <span> tags are used. The named arguments are used to set the attributes.
1 2 3 4 5 6 7 8 | tag_tokens(
tokens,
tag = "span",
span_adjacent = F,
doc_id = NULL,
unfold = NULL,
...
)
|
tokens |
a vector of tokens. |
tag |
The name of the tag to be used |
span_adjacent |
If TRUE, include adjacent tokens with identical attributes within the same tag |
doc_id |
If span_adjacent is TRUE, The document ids are required to ensure that tags do not span from one document to another. |
unfold |
Either a character vector or a named list of vectors of the same length as tokens. If given, all tokens with a tag can be clicked on to unfold the given text. If a list of vectors is given,
the values of the columns are concatenated with the column name. E.g. list(doc_id = 1, sentence = 1) will be [doc_id = 1, sentence = 2].
This only works if the tagged tokens are used in the html browser created with the |
... |
named arguments are used as attributes in the span tag for each token, with the name being the name of the attribute (e.g., class, . Each argument must be a vector of the same length as the number of tokens. NA values can be used to ignore attribute for a token, and if a token has NA for each attribute, it is not given a span tag. |
If a token does not have any attributes, the <span> tag is not added.
Note that the attr_style() function can be used to conveniently set the style attribute. Also, the set_col(), highlight_col() and scale_col() functions can be used to set the color of style attributes. See the example for illustration.
a character vector of tagged tokens
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | tag_tokens(tokens = c('token_1','token_2', 'token_3'),
class = c(1,1,2),
style = attr_style(color = set_col('red'),
`background-color` = highlight_col(c(FALSE,FALSE,TRUE))))
## tokens without attributes are not given a span tag
tag_tokens(tokens = c('token_1','token_2', 'token_3'),
class = c(1,NA,NA),
style = attr_style(color = highlight_col(c(TRUE,TRUE,FALSE))))
## span_adjacent can be used to put tokens with identical tags within one tag
## but then a doc_id has to be given as well
tag_tokens(tokens = c('token_1','token_2', 'token_3'),
class = c(1,1,NA),
span_adjacent=TRUE,
doc_id = c(1,1,1))
|
[1] "<span class=\"1\" style=\"color: rgba(255, 0, 0, 1)\">token_1</span>"
[2] "<span class=\"1\" style=\"color: rgba(255, 0, 0, 1)\">token_2</span>"
[3] "<span class=\"2\" style=\"color: rgba(255, 0, 0, 1); background-color: rgba(255, 255, 0, 1)\">token_3</span>"
[1] "<span class=\"1\" style=\"color: rgba(255, 255, 0, 1)\">token_1</span>"
[2] "<span style=\"color: rgba(255, 255, 0, 1)\">token_2</span>"
[3] "token_3"
[1] "<span class=\"1\">token_1" "token_2</span>"
[3] "token_3"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.