4 Prerequisites

In this chapter we get you set up and running with the twinetverse, namely installing the packages and setting up rtweet to fetch tweets.

4.1 Install

The package is available from Github can be installed with devtools (Wickham, Hester, and Chang 2018) or remotes (Csárdi et al. 2018). First install the remotes package with:


Then install the twinetverse with:


In the book we don’t explicitly load the package and assume you have it loaded in your environment (snippet below).


4.2 Setup rtweet

The rtweet package requires some set up. This is not only extremely easy but also very well explained on rtweet’s official website, so head over there if the short description below does not satisfy.

In essence, you will need a Twitter “app” to access its API, to create one:

  1. Head over to apps.twitter.com and login or signup if you do not have a Twitter account.
  2. Click create an app.
  3. In the following form, enter an app name, whatever you want, this does not matter.
  4. Enter a description, then again, it doesn’t matter.
  5. Under website, simply put a valid website, you can link to your Twitter profile if you do not have one, i.e.: https://twitter.com/jdatap
  6. Callback URL, this is important, in there put the following:, exactly as is.

You’re now setup with an app, take note of the crendentials of your app under “Keys and Access Tokens”, as you will need it to create your token and fetch tweets:

  • Consumer Key (consumer_key)
  • Consumer Secret (consumer_secret)
  • Access Token (access_token)
  • Access Token Secret (access_secret)

Do NOT share those credentials or your token with anyone.

Create your token with like so.


TK <- create_token(
  "My Application Name",
  consumer_key = "XxxxXxXXxXx",
  consumer_secret = "XxxxXxXXxXx",
  access_token = "XxxxXxXXxXx",
  access_secret = "XxxxXxXXxXx"

Ideally, also save it. There is no need to re-create a token everytime you want to download data. Once saved you can easily load it readRDS (we’ll demonstrate that in the next chapter).

saveRDS(TK, file = "token.rds")

You’re now all set to build Twitter networks!


Wickham, Hadley, Jim Hester, and Winston Chang. 2018. Devtools: Tools to Make Developing R Packages Easier. https://CRAN.R-project.org/package=devtools.

Csárdi, Gábor, Hadley Wickham, Winston Chang, Jim Hester, Martin Morgan, and Dan Tenenbaum. 2018. Remotes: R Package Installation from Remote Repositories, Including ’Github’. https://CRAN.R-project.org/package=remotes.