textfeatures: textfeatures

Description Usage Arguments Value Examples

View source: R/textfeatures.R

Description

Extracts features from text vector.

Usage

1
2
textfeatures(text, sentiment = TRUE, word_dims = NULL,
  normalize = TRUE, newdata = NULL, verbose = TRUE)

Arguments

text

Input data. Should be character vector or data frame with character variable of interest named "text". If a data frame then the first "id|*_id" variable, if found, is assumed to be an ID variable.

sentiment

Logical, indicating whether to return sentiment analysis features, the variables sent_afinn and sent_bing. Defaults to TRUE. Setting this to FALSE will speed things up a bit.

word_dims

Integer indicating the desired number of word2vec dimension estimates. When NULL, the default, this function will pick a reasonable number of dimensions (ranging from 2 to 200) based on size of input. To disable word2vec estimates, set this to 0 or FALSE.

normalize

Logical indicating whether to normalize (mean center, sd = 1) features. Defaults to TRUE.

newdata

If a textfeatures_model is supplied to text, supply this with new data to which you would like to apply the textfeatures_model.

verbose

A single logical for printing logging messages as work progresses.

Value

A tibble data frame with extracted features as columns.

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
## the text of five of Trump's most retweeted tweets
trump_tweets <- c(
  "#FraudNewsCNN #FNN https://t.co/WYUnHjjUjg",
  "TODAY WE MAKE AMERICA GREAT AGAIN!",
  paste("Why would Kim Jong-un insult me by calling me \"old,\" when I would",
    "NEVER call him \"short and fat?\" Oh well, I try so hard to be his",
    "friend - and maybe someday that will happen!"),
  paste("Such a beautiful and important evening! The forgotten man and woman",
    "will never be forgotten again. We will all come together as never before"),
  paste("North Korean Leader Kim Jong Un just stated that the \"Nuclear",
    "Button is on his desk at all times.\" Will someone from his depleted and",
    "food starved regime please inform him that I too have a Nuclear Button,",
    "but it is a much bigger &amp; more powerful one than his, and my Button",
    "works!")
)

## get the text features of a character vector
textfeatures(trump_tweets)

## data frame with a character vector named "text"
df <- data.frame(
  id = c(1, 2, 3),
  text = c("this is A!\t sEntence https://github.com about #rstats @github",
    "and another sentence here",
    "The following list:\n- one\n- two\n- three\nOkay!?!"),
  stringsAsFactors = FALSE
)

## get text features of a data frame with "text" variable
textfeatures(df)

textfeatures documentation built on Sept. 4, 2019, 1:05 a.m.