knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
clamour is a package to help with building a website to display the results of analysis of Twitter hashtags, usually associated with an event such as an academic conference. The package provides some basic infrastructure and examples to help you get set up.
library(clamour)
This vignette will take you through the basics of setting up a clamour project, analysis of an example dataset and how to host the results on a website using GitHub pages.
To start a clamour project we can use the clamour_setup
function. This will
create a basic directory structure with some template files. We just need to
provide the function with a path to the new project directory. For this vignette
we use a temporary directory.
path <- fs::path(tempdir(), "example") clamour_setup(path)
The result is the following directory structure:
analysis/
- Analysis files for each hashtag_site.yml
- Website configuration fileindex.Rmd
- Index pageabout.Rmd
- About pageEXAMPLE.Rmd
- An example hashtag analysis file_analysis.Rmd
- Analysis template that is applied to each hashtagdata/
- Data files containing tweetsEXAMPLE.Rds
- The example tweet datasetdocs/
- Rendered website files will go hereThe rtweet package is used to download tweets from Twitter but to do so it must first be authorised. The setup function will prompt you to run some code that should do this but if that is unsuccessful please refer to the information on the rtweet website.
When you want to add an analysis for a new hashtag or event you should run the
clamour_new
function. This function will create a new R Markdown document
based on the arguments you have provided. See the EXAMPLE.Rmd
file for an
example of what this looks like. Parameters for this analysis are provided in
the YAML section at the start of the file (see ?clamour_new
for more
description of these). After loading the tweet data there is an introduction
where you can describe the analysis in more detail. Most of the analysis is
performed by the chunk labelled analysis
which knits the _analysis.Rmd
file.
By having the analysis code in a separate file it is easy to update it in one
place and apply those changes to every analysis on your website.
To make sure that your new analysis will be accessible our your website remember
to render the index.html
file. The template for this file contains a call to
clamour_list()
which should automatically add a link to your new analysis.
Individual analysis files can be rendered by using rmarkdown::render()
or
pressing the "Knit" button in RStudio. Doing this should:
data/
directory_analysis.Rmd
filedocs/
directoryThe clamour template assumes that you will be serving your website using GitHub pages but it should also be possible use other similar services (with minor modifications). Details on setting up GitHub pages are available here but briefly the steps are:
docs/
directorydocs/
directoryBy default your website will be available at a URL like https://GITHUB-USER.github.io/REPOSITORY. You can see what the example website looks like here.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.