knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Here is an example script you can run to get a feel for how you might set up CSVs for a report.

Set up your account code & filter

Once you've set up an account code and filter, you can use this in your various metrics:

# First you'll want to set an account code
code <- "QUIR01BA" 

# Then set a filter - remember to add a brand
filter <- "published inthelast week and relevancy is relevant and brand isorchildof 10006"

If you want to find brand IDs from an account, look at the article on finding brands using R.

Getting volume and sentiment

# To use a function from chartingtest, you'll first need to load the library
library(chartingtest)

# Now you can get a breakdown of volume and sentiment (including net sentiment) by date
volume_sentiment_metric(code, filter)
library(chartingtest)
knitr::kable(volume_sentiment_metric(code, filter) %>% dplyr::mutate(positivePercent=scales::percent(positivePercent), neutralPercent=scales::percent(neutralPercent), negativePercent=scales::percent(negativePercent)), digits=2, format = "html") %>%
  kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)

Grouping by day, week or month

# You can group by day, week or month
volume_sentiment_metric(code, filter, group = "week")
knitr::kable(volume_sentiment_metric(code, filter) %>% dplyr::mutate(positivePercent=scales::percent(positivePercent), neutralPercent=scales::percent(neutralPercent), negativePercent=scales::percent(negativePercent)), digits=2) %>% 
  kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)

Saving to CSV

``` {r, eval=FALSE}

To save to CSV, set save=TRUE - you'll be asked to enter a filename

volume_sentiment_metric(code, filter, group = "day", save=TRUE)

If you want to run the code as part of a script, you can specify the file upfront and it will save automatically

volume_sentiment_metric(code, filter, group = "day", file="C:/Users/brandseye/Documents/volume_sentiment.csv")

## More examples

### Sentiment metric
```r
# Get data for the sentiment metric
sentiment_metric(code, filter)

``` {r, echo=FALSE} knitr::kable(sentiment_metric(code, filter) %>% dplyr::mutate(Percentage=scales::percent(Percentage))) %>% kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)

### Stats metric
```r
# Get data for the stats metric
stats_metric(code, filter)
knitr::kable(stats_metric(code, filter)) %>%
  kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)

Putting it all together

Here is an example of a script you might run to get all the CSVs for a particular report. In this example we will set the filter only once, but you could use multiple filters if you like, or add additional filtering to a particular metric.

How to run the example:

library(chartingtest)

# Loading 'glue' so we can set the folder name once and then stick it together with the filename
library(glue)

# Set account code to use
code <- "QUIR01BA" 

# Set the filter to use
filter <- "published inthelast week and relevancy is relevant and brand isorchildof 10006"

folder <- "PATH_TO_YOUR_FOLDER"

# Get the volume breakdown
volume_sentiment_metric(code, 
                        filter, 
                        file = glue(folder, "/volume-metric.csv")) # join the folder name onto the file name

# Get the hourly breakdown
time_of_day_metric(code, 
                   filter, 
                   file = glue(folder, "/time-of-day.csv"))

# Top 10 authors
authors_metric(code, 
               filter, 
               truncateAt = 10, #Only give me the first 10 authors
               glue(folder, "/authors-metric.csv"))

# Top 10 sites
sites_metric(code, 
             filter, 
             truncateAt = 10, #Only give me the first 10 sites
             file = glue(folder, "/sites-metric.csv"))

# Sentiment breakdown
sentiment_metric(code, 
                 filter, 
                 file = glue(folder, "/sentiment-metric.csv"))

# Top 10 words
wordcloud_metric(code, 
                 filter, 
                 file = glue(folder, "/wordcloud-metric.csv"))


brandseye/chartingtest documentation built on May 15, 2019, 3:17 p.m.