setting-up-script.Rmd
Here is an example script you can run to get a feel for how you might set up CSVs for a report.
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.
# 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)
published | count | netSentiment | netSentimentPercent | uniqueAuthors | positiveSentiment | positivePercent | negativeSentiment | negativePercent | neutralSentiment | neutralPercent |
---|---|---|---|---|---|---|---|---|---|---|
2018-08-30 | 0 | 0 | 0.00 | 0 | 0 | 0.0% | 0 | 0% | 0 | 0% |
2018-08-31 | 4 | 3 | 0.75 | 3 | 3 | 75.0% | 0 | 0% | 1 | 25% |
2018-09-01 | 5 | 0 | 0.00 | 2 | 0 | 0.0% | 0 | 0% | 5 | 100% |
2018-09-02 | 1 | 0 | 0.00 | 1 | 0 | 0.0% | 0 | 0% | 1 | 100% |
2018-09-03 | 0 | 0 | 0.00 | 0 | 0 | 0.0% | 0 | 0% | 0 | 0% |
2018-09-04 | 1 | 0 | 0.00 | 1 | 0 | 0.0% | 0 | 0% | 1 | 100% |
2018-09-05 | 3 | 1 | 0.33 | 2 | 1 | 33.3% | 0 | 0% | 2 | 67% |
2018-09-06 | 0 | 0 | 0.00 | 0 | 0 | 0.0% | 0 | 0% | 0 | 0% |
# You can group by day, week or month
volume_sentiment_metric(code, filter, group = "week")
published | count | netSentiment | netSentimentPercent | uniqueAuthors | positiveSentiment | positivePercent | negativeSentiment | negativePercent | neutralSentiment | neutralPercent |
---|---|---|---|---|---|---|---|---|---|---|
2018-08-30 | 0 | 0 | 0.00 | 0 | 0 | 0.0% | 0 | 0% | 0 | 0% |
2018-08-31 | 4 | 3 | 0.75 | 3 | 3 | 75.0% | 0 | 0% | 1 | 25% |
2018-09-01 | 5 | 0 | 0.00 | 2 | 0 | 0.0% | 0 | 0% | 5 | 100% |
2018-09-02 | 1 | 0 | 0.00 | 1 | 0 | 0.0% | 0 | 0% | 1 | 100% |
2018-09-03 | 0 | 0 | 0.00 | 0 | 0 | 0.0% | 0 | 0% | 0 | 0% |
2018-09-04 | 1 | 0 | 0.00 | 1 | 0 | 0.0% | 0 | 0% | 1 | 100% |
2018-09-05 | 3 | 1 | 0.33 | 2 | 1 | 33.3% | 0 | 0% | 2 | 67% |
2018-09-06 | 0 | 0 | 0.00 | 0 | 0 | 0.0% | 0 | 0% | 0 | 0% |
# 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")
# Get data for the sentiment metric
sentiment_metric(code, filter)
Sentiment | Count | Percentage |
---|---|---|
Negative | 0 | 0.0% |
Neutral | 5 | 71.4% |
Positive | 2 | 28.6% |
# Get data for the stats metric
stats_metric(code, filter)
Metric | Value |
---|---|
Volume | 14 |
Authors | 6 |
OTS | 18784 |
Engagement | 2 |
Sites | 3 |
Verified Sample | 7 |
Positive | 2 |
Neutral | 5 |
Negative | 0 |
Positive % | 28.6% |
Neutral % | 71.4% |
Negative % | 0% |
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:
PATH_TO_YOUR_FOLDER
with the folder where you’d like to save the CSVs, e.g. C:/Users/You/YourReportlibrary(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"))