prsp_stream: Stream comment scores with Perspective API

Description Usage Arguments Details Value Examples

View source: R/prsp_stream.R

Description

This function wraps prsp_score and loops over your text input. Provide a character string with your text and which scores you want to obtain. Make sure to keep track of your ratelimit with on the cloud console quota usage page.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
prsp_stream(
  .data,
  text = NULL,
  text_id = NULL,
  ...,
  safe_output = F,
  verbose = F,
  save = F,
  dt_name = "persp"
)

Arguments

.data

a dataset with a text and text_id column.

text

a character vector with text you want to score.

text_id

a unique ID for the text that you supply (required)

...

arguments passed to prsp_score. Don't forget to add the score_model argument (see peRspective::prsp_models for list of valid models).

safe_output

wraps the function into a purrr::safely environment (defaults to FALSE). Loop will run without pause and catch + output errors in a tidy tibble along with the results.

verbose

narrates the streaming procedure (defaults to FALSE).

save

NOT USABLE YET saves data into SQLite database (defaults to FALSE).

dt_name

NOT USABLE YET what is the name of the dataset? (defaults to persp).

Details

For more details see ?peRspective or Perspective API documentation

Value

a tibble

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
## Not run: 
## Create a mock tibble
text_sample <- tibble(
ctext = c("You wrote this? Wow. This is dumb and childish, please go f**** yourself.",
          "I don't know what to say about this but it's not good. The commenter is just an idiot",
          "This goes even further!",
          "What the hell is going on?",
          "Please. I don't get it. Explain it again",
          "Annoying and irrelevant! I'd rather watch the paint drying on the wall!"),
textid = c("#efdcxct", "#ehfcsct", 
           "#ekacxwt",  "#ewatxad", 
           "#ekacswt",  "#ewftxwd")
)
           
## GET TOXICITY and SEVERE_TOXICITY Scores for a dataset with a text column
text_sample %>%
prsp_stream(text = ctext,
            text_id = textid,
            score_model = c("TOXICITY", "SEVERE_TOXICITY"))
  
## Safe Output argument means will not stop on error
prsp_stream(text = ctext,
           text_id = textid,
           score_model = c("TOXICITY", "SEVERE_TOXICITY"),
           safe_output = T)
           
           
## verbose = T means you get pretty narration of your scoring procedure
prsp_stream(text = ctext,
           text_id = textid,
           score_model = c("TOXICITY", "SEVERE_TOXICITY"),
           safe_output = T,
           verbose = T)

## End(Not run)

peRspective documentation built on July 14, 2021, 9:06 a.m.