Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Latest commit

 

History

History
80 lines (52 loc) · 4.34 KB

Introduction_crossfire.md

File metadata and controls

80 lines (52 loc) · 4.34 KB

Introduction to crossfire

crossfire is a package created to give easier access to the datasets of the project Fogo Cruzado, which is a digital collaboration platform to register gun shootings in the metropolitan areas of Rio de Janeiro and Recife.

The package facilitates data extraction from the project open-data API, developed by Volt Data Lab.

Please note that as of Nov. 2020, due to changes in Fogo Cruzado's API, user's should update crossfire to its' 0.2.0 version. The get_fogocruzado() function from the 0.1.0 version returns errors and cannot be used.

Installing and loading the package

Currently, the crossfire package can be installed directly from its GitHub repository:

if (!require("devtools")) install.packages("devtools")
devtools::install_github("voltdatalab/crossfire")

Once installed, it can be loaded using the library function.

library(crossfire)

Functions

crossfire has 3 functions: fogocruzado_signin, get_fogocruzado and get_cities. Below, we explain how they can be used.

fogocruzado_signin

To access Fogo Cruzado's API, users should be registered and insert their e-mail and password for authentication. fogocruzado_signin function registers these information on the current R session, so that it can be used to obtain the Bearer token to extract data using the API.

As noted, the function sets the e-mail and password in the current R environment. Thus, users should repeat this operation on every new R session in which they intend to use the crossfire package. We note that user and password are personal. Therefore, users should be careful when writing and saving them in R scripts, in order to avoid sharing these information.

# Registers user and password
fogocruzado_signin(email = "example@account_exeample.com", password = "pass")

get_fogocruzado

crossfire main function is get_fogocruzado. It allows the extraction from slices to the whole dataset of shootings registered by Fogo Cruzado. The function returns a data frame, in which each line corresponds to a shooting registered and its information. The function has the following arguments: city, initial_date, final_date, state, and security_agent.

  • city allows to filter the observations by some cities. Their default returns all observations. The complete list of cities can be found using the get_cities function.
# Extract data for all registered shootings
fogocruzado_all <- get_fogocruzado()

# Extract data for shootings in the cities of Rio de Janeiro and Recife
fogocruzado_rj_recife <- get_fogocruzado(city = c("Rio de Janeiro", "Recife"))
# Extract all data from 2018
fogocruzado_2018 <- get_fogocruzado(initial_date = "2018-07-01", final_date = "2018-12-31")
  • state let users filter occurences according to the country's state where they happened. Default returns all observations.
# Get all data from shootings registered in Pernambuco
fogocruzado_pe <- get_fogocruzado(state = "PE")
  • security_agent allows users to select shootings according to the presence of security agents in the occurrence, assuming the value of security_agent = 1 when they are present, and security_agent = 0 - when they're not.
# Extract data from occurents where security agents were present
fogocruzado_security <- get_fogocruzado(security_agent = 1)

get_cities

get_cities() returns a data.frame with information about all cities from the Rio de Janeiro and Recife metropolitan areas covered by the Fogo Cruzado initiative.

cities <- get_cities()