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 |
Add counts to a tibble of cases
ojo_add_counts(data, vars = NULL, ...)
ojo_add_counts(data, vars = NULL, ...)
data |
A tibble returned by an |
vars |
Variable names from the |
... |
Placeholder for future arguments |
A tibble with counts for each case
## Not run: ojo_crim_cases(vars = c("counts", "open_counts")) |> ojo_add_counts() ## End(Not run)
## Not run: ojo_crim_cases(vars = c("counts", "open_counts")) |> ojo_add_counts() ## End(Not run)
Add issues to civil cases
ojo_add_issues(data, vars = NULL, ...)
ojo_add_issues(data, vars = NULL, ...)
data |
A lazy tibble of civil cases |
vars |
A character vector of variables to return |
... |
Placeholder for additional arguments |
data, a lazy tibble containing the resulting civil cases
## Not run: ojo_civ_cases() |> ojo_add_issues() ## End(Not run)
## Not run: ojo_civ_cases() |> ojo_add_issues() ## End(Not run)
Query the Open Justice Oklahoma database for the minutes of a case
ojo_add_minutes(data, ...)
ojo_add_minutes(data, ...)
data |
A lazy tibble containing the cases to query |
... |
Placeholder for additional arguments |
A lazy tibble containing the resulting cases with minutes
## Not run: ojo_add_minutes() ## End(Not run)
## Not run: ojo_add_minutes() ## End(Not run)
Query the Open Justice Oklahoma database for party details
ojo_add_party_details(data, vars = NULL, ...)
ojo_add_party_details(data, vars = NULL, ...)
data |
A lazy tibble containing the results of a parties query |
vars |
A character vector of variables to return |
... |
Placeholder for additional arguments |
data, a lazy tibble containing the resulting party details
## Not run: ojo_add_party_details() ## End(Not run)
## Not run: ojo_add_party_details() ## End(Not run)
Configure credentials for the Open Justice Oklahoma database
ojo_auth( host, port, username, password, ..., .admin = F, .overwrite = T, .install = T )
ojo_auth( host, port, username, password, ..., .admin = F, .overwrite = T, .install = T )
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 |
Assists the user in populating a .Renviron file with the necessary environment variables to connect to the Open Justice Oklahoma database.
Nothing
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.
## Not run: ojo_auth() ## End(Not run)
## Not run: ojo_auth() ## End(Not run)
Returns a tibble containing all the case types present in the OJO database
ojo_case_types()
ojo_case_types()
Tibble of case types
## Not run: ojo_case_types() ## End(Not run)
## Not run: ojo_case_types() ## End(Not run)
Check whether the database connection is using SSL properly
ojo_check_ssl(..., .con = NULL)
ojo_check_ssl(..., .con = NULL)
... |
Placeholder |
.con |
The ojodb connection to use |
A logical indicator of whether the db connection is properly using SSL
## Not run: # Identifies the table ojo_check_ssl() ## End(Not run)
## Not run: # Identifies the table ojo_check_ssl() ## End(Not run)
Query the Open Justice Oklahoma database for civil cases with a case type of 'SC' (small claims)
ojo_civ_cases( districts = "all", vars = NULL, case_types = c("CS", "SC", "CJ"), file_years = lubridate::year(Sys.Date()), ... )
ojo_civ_cases( districts = "all", vars = NULL, case_types = c("CS", "SC", "CJ"), file_years = lubridate::year(Sys.Date()), ... )
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 |
data, a lazy tibble containing the resulting civil cases
## 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)
## 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)
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.
ojo_collect(.data, ..., .silent = !rlang::is_interactive())
ojo_collect(.data, ..., .silent = !rlang::is_interactive())
.data |
The lazy tibble to be pulled |
... |
Placeholder for additional arguments |
.silent |
Should the command line interface elements be shown? Defaults to |
A local tibble
## Not run: ojo_crim_cases() |> head(100) |> ojo_collect() ## End(Not run)
## Not run: ojo_crim_cases() |> head(100) |> ojo_collect() ## End(Not run)
Add OJO styling to a ggplot
ojo_color(numbers = 1:8)
ojo_color(numbers = 1:8)
numbers |
A vector of numbers to use for the color palette |
## 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)
## 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)
Connect to the Open Justice Oklahoma database
ojo_connect( ..., .admin = FALSE, .driver = "RPostgres", .global = lifecycle::deprecated(), .env = ojo_env(), .pool = FALSE )
ojo_connect( ..., .admin = FALSE, .driver = "RPostgres", .global = lifecycle::deprecated(), .env = ojo_env(), .pool = FALSE )
... |
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 |
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.
A database connection object created with RPostgres::Postgres()
and either pool::dbPool
or DBI::dbConnect
A connection object (named ojo_con
or ojo_pool
depending on the .pool
argument) is created in the package environment.
ojo_auth()
## Not run: ojo_connect() ## End(Not run)
## Not run: ojo_connect() ## End(Not run)
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.
ojo_county_population(years)
ojo_county_population(years)
years |
A numeric vector of years for which to get population data |
A table of Oklahoma's population by county in each year specified
## Not run: ojo_county_population(2018) ## End(Not run)
## Not run: ojo_county_population(2018) ## End(Not run)
Query the Open Justice Oklahoma database for criminal cases with a case type of 'CM' (misdemeanor) or 'CF' (felony)
ojo_crim_cases( districts = "all", vars = NULL, case_types = c("CM", "CF", "TR"), file_years = 2000:lubridate::year(Sys.Date()), ... )
ojo_crim_cases( districts = "all", vars = NULL, case_types = c("CM", "CF", "TR"), file_years = 2000:lubridate::year(Sys.Date()), ... )
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 |
data, a lazy tibble containing the resulting criminal cases
## 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)
## 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)
Get the environment of the OJO package, which holds the database pool object.
ojo_env(...)
ojo_env(...)
... |
Placeholder for future arguments |
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.
ojo_eviction_cases( districts = "all", ..., date_start = NULL, date_end = NULL, more_case_variables = NULL, more_issue_variables = NULL, get_judgments = TRUE )
ojo_eviction_cases( districts = "all", ..., date_start = NULL, date_end = NULL, more_case_variables = NULL, more_issue_variables = NULL, get_judgments = TRUE )
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 |
A dataframe containing eviction data
## 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)
## 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
ojo_fill(numbers = 1:8)
ojo_fill(numbers = 1:8)
numbers |
A vector of numbers to use for the color palette |
## 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)
## 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)
Returns the Oklahoma state fiscal year (July 1 - June 30) in which a given Date falls.
ojo_fiscal_year(date)
ojo_fiscal_year(date)
date |
An atomic value of class Date |
Fiscal year of a Date as an integer
## Not run: ojo_fiscal_year(ymd("2018-06-30")) # Returns 2018 ojo_fiscal_year(ymd("2018-07-01")) # Returns 2019 ## End(Not run)
## Not run: ojo_fiscal_year(ymd("2018-06-30")) # Returns 2018 ojo_fiscal_year(ymd("2018-07-01")) # Returns 2019 ## End(Not run)
Query the Open Justice Oklahoma database for the names of all schemas
ojo_list_schemas(..., .con = NULL)
ojo_list_schemas(..., .con = NULL)
... |
Placeholder |
.con |
The OJO database connection to use |
data, a tibble containing the names of all schemas
## Not run: ojo_list_schemas() ## End(Not run)
## Not run: ojo_list_schemas() ## End(Not run)
Query the Open Justice Oklahoma database for the names of all tables
ojo_list_tables(schema = "public", ..., .con = NULL)
ojo_list_tables(schema = "public", ..., .con = NULL)
schema |
The name of the schema to query |
... |
Placeholder for additional arguments |
.con |
The OJO database connection to use |
data, a tibble containing the names of all tables
## Not run: ojo_list_tables() ojo_list_tables("all") ojo_list_tables("iic") ## End(Not run)
## Not run: ojo_list_tables() ojo_list_tables("all") ojo_list_tables("iic") ## End(Not run)
Query the Open Justice Oklahoma database for the names of all variables in a table
ojo_list_vars(table, schema = "public", ..., .con = NULL)
ojo_list_vars(table, schema = "public", ..., .con = NULL)
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 |
data, a tibble containing the names of all variables in a table
## Not run: ojo_list_vars("case") ojo_list_vars("inmate", "iic") ## End(Not run)
## Not run: ojo_list_vars("case") ojo_list_vars("inmate", "iic") ## End(Not run)
Add OJO styling to a ggplot
ojo_pal
ojo_pal
An object of class character
of length 8.
## 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)
## 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)
Query the Open Justice Oklahoma database
ojo_query(query, ..., .con = NULL)
ojo_query(query, ..., .con = NULL)
query |
The query to send to ojodb |
... |
Arguments to pass to glue::glue_sql |
.con |
The ojodb connection to use |
data, a tibble containing the results of the query
## Not run: ojo_query("SELECT * FROM \"case\" LIMIT 10") ojo_query("SELECT * FROM iic.inmate LIMIT 10") ## End(Not run)
## Not run: ojo_query("SELECT * FROM \"case\" LIMIT 10") ojo_query("SELECT * FROM iic.inmate LIMIT 10") ## End(Not run)
Query the Open Justice Oklahoma database for minutes matching a search term
ojo_search_minutes(query, ..., .con = NULL, .silent = F)
ojo_search_minutes(query, ..., .con = NULL, .silent = F)
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 |
data, a lazy tibble containing the resulting minutes
## 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)
## 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)
Displays the OSCN court record for a given row in a dataframe with columns named court
and casenum
ojo_show_row(df, row_number)
ojo_show_row(df, row_number)
df |
A local dataframe with columns named |
row_number |
The number of the row of the case to be shown |
Nothing
Opens a browser window to the OSCN court record
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()
.
ojo_tbl(table, schema = "public", ..., .con = NULL, .source = "postgres")
ojo_tbl(table, schema = "public", ..., .con = NULL, .source = "postgres")
A pointer to a table that can be passed to dplyr functions and/or pulled into a dataframe using ojo_collect()
ojo_list_tables(), ojo_list_vars(), ojo_list_schemas()
## 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)
## 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)
Add OJO styling to a ggplot
ojo_theme()
ojo_theme()
## 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)
## 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)
Returns the version of the ojodb
package.
ojo_version(...)
ojo_version(...)
... |
Placeholder for future arguments |
A character vector containing the version number of the ojodb
package.