Package 'ojoutils'

Title: A Collection of Nifty Functions and Objects for OJO Analysts
Description: We find ourselves repeating the same simple tasks or running a series of R commands over and over again. No more!
Authors: Brancen Gregory [aut, cre], Andrew Bell [aut]
Maintainer: Brancen Gregory <[email protected]>
License: GPL (>= 3)
Version: 0.1.3
Built: 2025-02-06 00:15:49 UTC
Source: https://github.com/openjusticeok/ojoutils

Help Index


Describe Change

Description

Generate descriptive statements about changes between two values.

Usage

describe_change(
  before,
  after,
  input_unit,
  output_unit,
  template = NULL,
  direction_phrases = c(increase = "increased by", decrease = "decreased by", none =
    "remained unchanged"),
  include_values = FALSE
)

Arguments

before

The initial numeric value to compare. For some unit combinations before must be non-zero to avoid divide-by-zero errors.

after

The numeric value to compare to the initial value.

input_unit

One of "number", "percent", or "ratio". Determines how the before and after values are treated.

output_unit

One of "number", "percent", "times", or "points". "points" may only be used when input_unit is "percent" or "ratio".

template

A {glue} template for the string returned when there is a change. Defaults are provided based on output_unit. Possible template variables are: direction, change, and unit.

direction_phrases

A named vector with three items: "increase", "decrease", and "none", used to customize either the default or custom template.

include_values

A logical value indicating whether to include before and after in the change description string.

Value

A string describing the change between two values, optionally including the values themselves.

Examples

# Basic usage with defaults
describe_change(
  before = 1,
  after = 0.5,
  input_unit = "ratio",
  output_unit = "percent",
)
#> decreased by 50 percent

# Using different phrasing for changes
describe_change(
  before = 33,
  after = 66,
  input_unit = "percent",
  output_unit = "percent",
  direction_phrases = c(
    increase = "rose by",
    decrease = "fell by",
    none = "stagnated"
  )
)
#> rose by 100 percent

# Customizing the template
describe_change(
  before = 10,
  after = 12,
  input_unit = "number",
  output_unit = "number",
  template = "{direction} {change} people"
)
#> increased by 2 people

Directory Empty?

Description

Takes a path and determines whether it is empty.

Usage

dir_empty(path)

Arguments

path

A relative or absolute path to the directory to test.

Value

TRUE if the directory is empty, otherwise FALSE. If the directory doesn't exist, or the string supplied to path isn't recognized as a valid path, then the function returns an error.


Limit

Description

A thin wrapper around head to sooth the pain of context switching between R and SQL

Usage

limit(x, ...)

Arguments

x

The object to limit

...

Additional arguments to head

Details

A thin wrapper around head that allows limit to be used in place of head. This is useful because sometimes it is hard to context switch between R and SQL. It can be used on lazy data frames since this package imports dbplyr.

Value

The limited object


Oklahoma Counties

Description

Oklahoma Counties

Usage

ojo_counties

Format

An object of class character of length 77.


Create Project

Description

Creates a new R project with a standard directory structure

Usage

ojo_create_project(
  name = NULL,
  description = NULL,
  dir = ".",
  private = TRUE,
  packages = NULL
)

Getting Started

To learn more about creating projects, see the vignette: vignette("project-creation", package = "ojotools")


Parse Oklahoma Counties

Description

Parse Oklahoma Counties

Usage

ojo_parse_county(
  county,
  ...,
  case = "lower",
  squish = NULL,
  suffix = NULL,
  counties = ojo_counties,
  .silent = FALSE
)

Arguments

county

A string or character vector that represents an Oklahoma county

...

Placeholder for future arguments

case

The case to format the county string to. One of "lower", "upper", or "title".

squish

A boolean indicator of whether to remove whitespace

suffix

Specification of a suffix to remove from each item in county. For example, " County, OK".

counties

A vector of valid county names to match on.

.silent

A currently unused argument.


Function to use the OJO quarto HTML template

Description

Wrapper for ⁠quarto use template⁠ command. Defaults to OJO html template.

Usage

ojo_use_template(path, template = "openjusticeok/ojo-report-template")

Arguments

path

The name of the directory where the template should be added. This should be a string representing an absolute path, or a path relative to the current working directory.

template

The name of the Quarto template to use. This should be a string in the format "username/repository". Default is "openjusticeok/ojo-report-template".

Value

This function does not return a value. If the user chooses not to proceed with the operation, the function exits silently.

Examples

## Not run: 
ojo_use_template(template = "openjusticeok/ojo-report-template", path = "my_directory")

## End(Not run)