Package 'ojodb'

Title: Analyze Data from the Open Justice Oklahoma Database
Description: {ojodb} provides convenient functions to query court data from the Open Justice Oklahoma database.
Authors: Brancen Gregory [cre, aut], Ryan Gentzler [aut], Andrew Bell [aut], Anthony Flores [aut], Elizabeth Spencer [ctb]
Maintainer: Brancen Gregory <[email protected]>
License: GPL (>= 3)
Version: 2.10.0
Built: 2024-11-11 05:32:39 UTC
Source: https://github.com/openjusticeok/ojodb

Help Index


Add counts to a tibble of cases

Description

Add counts to a tibble of cases

Usage

ojo_add_counts(data, vars = NULL, ...)

Arguments

data

A tibble returned by an ojo_ prefixed function

vars

Variable names from the count table to include

...

Placeholder for future arguments

Value

A tibble with counts for each case

Examples

## Not run: 
ojo_crim_cases(vars = c("counts", "open_counts")) |>
  ojo_add_counts()

## End(Not run)

Add issues to civil cases

Description

Add issues to civil cases

Usage

ojo_add_issues(data, vars = NULL, ...)

Arguments

data

A lazy tibble of civil cases

vars

A character vector of variables to return

...

Placeholder for additional arguments

Value

data, a lazy tibble containing the resulting civil cases

Examples

## Not run: 
ojo_civ_cases() |>
 ojo_add_issues()

## End(Not run)

Query minutes for a given case

Description

Query the Open Justice Oklahoma database for the minutes of a case

Usage

ojo_add_minutes(data, ...)

Arguments

data

A lazy tibble containing the cases to query

...

Placeholder for additional arguments

Value

A lazy tibble containing the resulting cases with minutes

Examples

## Not run: 
ojo_add_minutes()

## End(Not run)

Add party details to a parties query

Description

Query the Open Justice Oklahoma database for party details

Usage

ojo_add_party_details(data, vars = NULL, ...)

Arguments

data

A lazy tibble containing the results of a parties query

vars

A character vector of variables to return

...

Placeholder for additional arguments

Value

data, a lazy tibble containing the resulting party details

Examples

## Not run: 
ojo_add_party_details()

## End(Not run)

Create configuration for OJO database connection

Description

Configure credentials for the Open Justice Oklahoma database

Usage

ojo_auth(
  host,
  port,
  username,
  password,
  ...,
  .admin = F,
  .overwrite = T,
  .install = T
)

Arguments

host

The host name of the database server

port

The port number of the database server

username

The username to use to connect to the database

password

The password to use to connect to the database

...

Placeholder for additional arguments

.admin

A logical value indicating whether to connect to the database as an administrator

.overwrite

A logical value indicating whether to overwrite the existing .Renviron file

.install

A logical value indicating whether to install the database connection or use it only for the current session

Details

Assists the user in populating a .Renviron file with the necessary environment variables to connect to the Open Justice Oklahoma database.

Value

Nothing

Side Effects

The first time this function is run, it will prompt the user for a username, password, and host name. It will then store these credentials in the user's .Renviron file. If the .Renviron file already exists, it will be backed up and the new credentials will be appended to the end of the file. If the .Renviron file does not exist, it will be created and the credentials will be stored there.

Examples

## Not run: 
ojo_auth()

## End(Not run)

List the case types present in the OJO database

Description

Returns a tibble containing all the case types present in the OJO database

Usage

ojo_case_types()

Value

Tibble of case types

Examples

## Not run: 
ojo_case_types()

## End(Not run)

Check whether the database connection is using SSL properly

Description

Check whether the database connection is using SSL properly

Usage

ojo_check_ssl(..., .con = NULL)

Arguments

...

Placeholder

.con

The ojodb connection to use

Value

A logical indicator of whether the db connection is properly using SSL

Examples

## Not run: 
# Identifies the table
ojo_check_ssl()

## End(Not run)

Query civil cases from the OJO database

Description

Query the Open Justice Oklahoma database for civil cases with a case type of 'SC' (small claims)

Usage

ojo_civ_cases(
  districts = "all",
  vars = NULL,
  case_types = c("CS", "SC", "CJ"),
  file_years = lubridate::year(Sys.Date()),
  ...
)

Arguments

districts

A character vector of districts to query

vars

A character vector of variables to return

case_types

A character vector of case types to query

file_years

A character vector of years to query

...

Placeholder for additional arguments

Value

data, a lazy tibble containing the resulting civil cases

Examples

## Not run: 
ojo_civ_cases()
ojo_civ_cases(districts = c("TULSA", "ADAIR"))
ojo_civ_cases(vars = "all")
ojo_civ_cases(vars = c("updated_at", "created_at"))

## End(Not run)

OJO Collect

Description

A wrapper for dplyr::collect() that includes a progress bar Pull a lazy tibble into your local environment from the OJO database, using ojo_crim_cases(), ojo_civ_cases(), etc.

Usage

ojo_collect(.data, ..., .silent = !rlang::is_interactive())

Arguments

.data

The lazy tibble to be pulled

...

Placeholder for additional arguments

.silent

Should the command line interface elements be shown? Defaults to TRUE if the user is in an interactive session, and FALSE if they are not.

Value

A local tibble

Examples

## Not run: 
ojo_crim_cases() |>
 head(100) |>
 ojo_collect()

## End(Not run)

Add OJO styling to a ggplot

Description

Add OJO styling to a ggplot

Usage

ojo_color(numbers = 1:8)

Arguments

numbers

A vector of numbers to use for the color palette

Examples

## Not run: 
ggplot(ojo_example, aes(file_year, n_cases, color = court)) +
  geom_line(size = 1.5) +
  theme_ojo() +
  ojo_color() +
  scale_x_continuous(
    breaks = 2010:2019,
    limits = c(NA, 2019)
  )

## End(Not run)

OJO Connect

Description

Connect to the Open Justice Oklahoma database

Usage

ojo_connect(
  ...,
  .admin = FALSE,
  .driver = "RPostgres",
  .global = lifecycle::deprecated(),
  .env = ojo_env(),
  .pool = FALSE
)

Arguments

...

Placeholder.

.admin

A logical value indicating whether to connect to the database as an administrator.

.driver

The driver to use for the connection. Default is "RPostgres". "duckdb" is also supported.

.global

Deprecated. A connection will always be created in the specified environment, or in the package environment by default.

.env

The environment in which you want the connection stored.

.pool

A logical value indicating whether to use a connection pool from the {pool} package, or not.

Details

Opens a connection to the Open Justice Oklahoma database using credentials stored in the .Renviron file. If no credentials exist, prompts for user, password, and host name and provides instructions to store them for future sessions.

Value

A database connection object created with RPostgres::Postgres() and either pool::dbPool or DBI::dbConnect

Side Effects

A connection object (named ojo_con or ojo_pool depending on the .pool argument) is created in the package environment.

See Also

ojo_auth()

Examples

## Not run: 
ojo_connect()

## End(Not run)

Get population data by county for Oklahoma from the Census Bureau's American Community Survey

Description

Summarizes and manipulates the PEP series to return Oklahoma's population by county for desired years. Useful for calculating per capita rates of county-level data.

Usage

ojo_county_population(years)

Arguments

years

A numeric vector of years for which to get population data

Value

A table of Oklahoma's population by county in each year specified

Examples

## Not run: 
ojo_county_population(2018)

## End(Not run)

Query criminal cases from the OJO database

Description

Query the Open Justice Oklahoma database for criminal cases with a case type of 'CM' (misdemeanor) or 'CF' (felony)

Usage

ojo_crim_cases(
  districts = "all",
  vars = NULL,
  case_types = c("CM", "CF", "TR"),
  file_years = 2000:lubridate::year(Sys.Date()),
  ...
)

Arguments

districts

A character vector of districts to query

vars

A character vector of variables to return

case_types

A character vector of case types to query

file_years

A character vector of years to query

...

Placeholder for additional arguments

Value

data, a lazy tibble containing the resulting criminal cases

Examples

## Not run: 
ojo_crim_cases()
ojo_crim_cases(districts = c("TULSA", "ADAIR"))
ojo_crim_cases(vars = "all")
ojo_crim_cases(vars = c("updated_at", "created_at"))

## End(Not run)

OJO Environment

Description

Get the environment of the OJO package, which holds the database pool object.

Usage

ojo_env(...)

Arguments

...

Placeholder for future arguments


OJO Eviction Cases

Description

Collects Oklahoma eviction data for the specified districts (or all of Oklahoma) for the user specified time frame. If date_end is not specified, the most up-to-date data will be collected.

Function uses the latest methodology we use for identifying eviction cases and outcomes in Oklahoma. As that methodology is updated, this function will be updated to reflect those changes.

Usage

ojo_eviction_cases(
  districts = "all",
  ...,
  date_start = NULL,
  date_end = NULL,
  more_case_variables = NULL,
  more_issue_variables = NULL,
  get_judgments = TRUE
)

Arguments

districts

District codes for which to collect data (default is "all", which collects data for all districts)

...

Placeholder for additional arguments

date_start

Start date for the data collection period

date_end

End date for the data collection period (default is NULL, which collects the most up-to-date data)

more_case_variables

Additional variables from case table to include in the output

more_issue_variables

Additional variables from issue table to include in the output

get_judgments

Logical value indicating whether to include eviction judgment information in the output

Value

A dataframe containing eviction data

Examples

## Not run: 
ojo_eviction_cases()
ojo_eviction_cases(districts = c("TULSA", "ADAIR"))
ojo_eviction_cases(
  districts = c("TULSA", "ADAIR"),
  date_start = "2020-01-01",
  date_end = "2020-01-31",
  more_issue_variables = disposition_date
)
ojo_eviction_cases(
  districts = c("TULSA", "ADAIR"),
  get_judgments = TRUE
)

## End(Not run)

Add OJO styling to a ggplot

Description

Add OJO styling to a ggplot

Usage

ojo_fill(numbers = 1:8)

Arguments

numbers

A vector of numbers to use for the color palette

Examples

## Not run: 
ggplot(ojo_example, aes(file_year, n_cases, color = court)) +
  geom_line(size = 1.5) +
  theme_ojo() +
  ojo_color() +
  scale_x_continuous(
    breaks = 2010:2019,
    limits = c(NA, 2019)
  )

## End(Not run)

Determine the Oklahoma state fiscal year that a Date falls in

Description

Returns the Oklahoma state fiscal year (July 1 - June 30) in which a given Date falls.

Usage

ojo_fiscal_year(date)

Arguments

date

An atomic value of class Date

Value

Fiscal year of a Date as an integer

Examples

## Not run: 
ojo_fiscal_year(ymd("2018-06-30"))
# Returns 2018

ojo_fiscal_year(ymd("2018-07-01"))
# Returns 2019

## End(Not run)

List all schemas on the OJO database

Description

Query the Open Justice Oklahoma database for the names of all schemas

Usage

ojo_list_schemas(..., .con = NULL)

Arguments

...

Placeholder

.con

The OJO database connection to use

Value

data, a tibble containing the names of all schemas

Examples

## Not run: 
ojo_list_schemas()

## End(Not run)

List all tables on the OJO database

Description

Query the Open Justice Oklahoma database for the names of all tables

Usage

ojo_list_tables(schema = "public", ..., .con = NULL)

Arguments

schema

The name of the schema to query

...

Placeholder for additional arguments

.con

The OJO database connection to use

Value

data, a tibble containing the names of all tables

Examples

## Not run: 
ojo_list_tables()
ojo_list_tables("all")
ojo_list_tables("iic")

## End(Not run)

List all variables in a table on the ojodb database

Description

Query the Open Justice Oklahoma database for the names of all variables in a table

Usage

ojo_list_vars(table, schema = "public", ..., .con = NULL)

Arguments

table

The name of the table to query

schema

The name of the schema to query

...

Placeholder for additional arguments

.con

The ojodb connection to use

Value

data, a tibble containing the names of all variables in a table

Examples

## Not run: 
ojo_list_vars("case")
ojo_list_vars("inmate", "iic")

## End(Not run)

Add OJO styling to a ggplot

Description

Add OJO styling to a ggplot

Usage

ojo_pal

Format

An object of class character of length 8.

Examples

## Not run: 
ggplot(ojo_example, aes(file_year, n_cases, color = court)) +
  geom_line(size = 1.5) +
  theme_ojo() +
  ojo_color() +
  scale_x_continuous(
    breaks = 2010:2019,
    limits = c(NA, 2019)
  )

## End(Not run)

OJO Query

Description

Query the Open Justice Oklahoma database

Usage

ojo_query(query, ..., .con = NULL)

Arguments

query

The query to send to ojodb

...

Arguments to pass to glue::glue_sql

.con

The ojodb connection to use

Value

data, a tibble containing the results of the query

Examples

## Not run: 
ojo_query("SELECT * FROM \"case\" LIMIT 10")
ojo_query("SELECT * FROM iic.inmate LIMIT 10")

## End(Not run)

Query minutes for a given search term

Description

Query the Open Justice Oklahoma database for minutes matching a search term

Usage

ojo_search_minutes(query, ..., .con = NULL, .silent = F)

Arguments

query

A term or phrase to search for using the PostgreSQL full text search syntax

...

Placeholder

.con

The OJO connection to use

.silent

Should the command line interface elements be shown? Defaults to TRUE if the user is in an interactive session, and FALSE if they are not.

Value

data, a lazy tibble containing the resulting minutes

Examples

## Not run: 

# Minutes containing words like 'mcgirt'
ojo_search_minutes("mcgirt")

# Minutes containing 'mcgirt' AND 'jursdiction
ojo_search_minutes("mcgirt & jurisdiction")

# Minutes containing 'mcgirt' OR 'jurisdiction
ojo_search_minutes("mcgirt | jurisdiction")

# Minutes NOT containing 'mcgirt'
## Use sparingly! It is likely to return rows in the hundreds of thousands or millions!
ojo_search_minutes("!! mcgirt")

# Minutes containing 'tribal' FOLLOWED BY 'jurisdiction'
ojo_search_minutes("tribal <-> jurisdiction")

## End(Not run)

Browse the source court record of a row

Description

Displays the OSCN court record for a given row in a dataframe with columns named court and casenum

Usage

ojo_show_row(df, row_number)

Arguments

df

A local dataframe with columns named court and casenum

row_number

The number of the row of the case to be shown

Value

Nothing

Side effects

Opens a browser window to the OSCN court record


Identify a table from the OJO database

Description

Identifies a table in the OJO database from which to query data. Remember to run connect_ojo() to establish a connection before attempting to query and to close the connection afterwards with disconnect_ojo().

Usage

ojo_tbl(table, schema = "public", ..., .con = NULL, .source = "postgres")

Arguments

table

The name of a table in the OJO database. To get a list of tables, run ojo_list_tables()

schema

The name of a schema in the OJO database. To get a list of schemas, run ojo_list_schemas()

...

Placeholder

.con

The ojodb connection to use

.source

[Experimental] The source of the table. Options are 'postgres', 'gcs_duckdb', and 'gcs_arrow'. Default is 'postgres'.

Value

A pointer to a table that can be passed to dplyr functions and/or pulled into a dataframe using ojo_collect()

See Also

ojo_list_tables(), ojo_list_vars(), ojo_list_schemas()

Examples

## Not run: 
# Identifies the table
ojo_tbl("case")

# Pulls down case information data for every Tulsa felony filed in 2020 into a dataframe d
d <- ojo_tbl("case") %>%
  filter(district == "TULSA", case_type == "CF", year == 2020) %>%
  collect()

## End(Not run)

Style a ggplot in the OJO style

Description

Add OJO styling to a ggplot

Usage

ojo_theme()

Examples

## Not run: 
ggplot(ojo_example, aes(file_year, n_cases, color = court)) +
  geom_line(size = 1.5) +
  ojo_theme() +
  ojo_colors() +
  scale_x_continuous(
    breaks = 2010:2019,
    limits = c(NA, 2019)
  )

## End(Not run)

OJO Version

Description

Returns the version of the ojodb package.

Usage

ojo_version(...)

Arguments

...

Placeholder for future arguments

Value

A character vector containing the version number of the ojodb package.