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

Introduction

This vignette documents how to interact with the Durham election violence database using R. The package can be installed from the repository on github. If the package has previously been installed, reinstalling the package from github will also get the latest updates:

devtools::install_github("gidonc/durhamevp")

You can then load all the functions with the following command:

library(durhamevp)

Connecting to the Database

Connection to the database is implemented silently in connection functions in the package, but credentials are still needed.

You don't want to always have to re-enter the database password, so it is more convinient to store the password on your computer and pass it automatically to the database. This can be done using either the "config" package or the "keyring" package ("keyring" is more secure and should be the first option). These methods useful not only because the password only has to be entered once per computer, but also because they work without user interaction (e.g. when using knitr).

To use the database password needs to be stored on your computer. This can be done using the key_set command from keyring package:

keyring::key_set(service="evp", user="data_writer")

You will then be prompted to enter the password. Once entered in this way the password will be securely stored on your computer and should not need to be rentered (the password can be reset using the command above if e.g. the password changes).

If you need to connect to the database outside the package functions (for example to pass an SQL query to the database) use the evdb_connect function. The function needs to pass the password to the database. The default option (password_method = "ask") will prompt you for the password. This "ask" method for obtaining the password only works in RStudio and only in interactive mode (e.g. not when writing Rnw or Rmd files).

con <- evdb_connect()

To connect to the database as the default ("data_writer") user, using the password stored in the keyring use password_method="keyring":

con <- evdb_connect(password_method="keyring")


gidonc/durhamevp documentation built on April 8, 2022, 10:31 a.m.