Learn R Programming

LexisNexisTools (version 0.2.2)

lnt_lookup: Lookup keywords in articles

Description

This function looks for the provided pattern in the string or LNToutput object. This can be useful, for example, to see which of the keywords you used when retrieving the data was used in each article.

Usage

lnt_lookup(x, pattern, case_insensitive = FALSE,
  unique_pattern = FALSE, word_boundaries = TRUE, cores = NULL,
  verbose = TRUE)

Arguments

x

An LNToutput object or a string or vector of strings.

pattern

A character vector of keywords. Word boundaries before and after the keywords are honoured. Regular expression can be used.

case_insensitive

If FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

unique_pattern

If TRUE, duplicated mentions of the same pattern are removed.

word_boundaries

If TRUE, lookup is performed with word boundaries at beginning and end of the pattern (i.e., pattern "protest" will not identify "protesters" etc.).

cores

The number of CPU cores to use. Use NULL or 1 to turn off.

verbose

A logical flag indicating whether a status bar is printed to the screen.

Value

A list keyword hits.

Details

If an LNToutput object is provided, the function will look for the pattern in the headlines and articles. The returned object is a list of hits. If a regular expression is provided, the returned word will be the actual value from the text.

Examples

Run this code
# NOT RUN {
# Make LNToutput object from sample
LNToutput <- lnt_read(lnt_sample())

# Lookup keywords
LNToutput@meta$Keyword <- lnt_lookup(LNToutput,
                                     "statistical computing")

# Keep only articles which mention the keyword
LNToutput_stat <- LNToutput[!sapply(LNToutput@meta$Keyword, is.null)]

# Covert list of keywords to string
LNToutput@meta$Keyword <- sapply(LNToutput@meta$Keyword, toString)
# }

Run the code above in your browser using DataLab