Package 'planscorer'

Title: Score Redistricting Plans with 'PlanScore'
Description: Provides access to the 'PlanScore' Application Programming Interface (<https://github.com/PlanScore/PlanScore/blob/main/API.md>) for scoring redistricting plans. Allows for upload of plans from block assignment files and shape files. For shapes in memory, such as from 'sf' or 'redist', it processes them to save and upload. Includes tools for tidying responses and saving output from the website.
Authors: Christopher T. Kenny [aut, trl, cre] (R port, <https://orcid.org/0000-0002-9386-6860>), Michal Migurski [aut] (python original, https://github.com/PlanScore/PlanScore-CLI), Cory McCartan [art]
Maintainer: Christopher T. Kenny <[email protected]>
License: MIT + file LICENSE
Version: 0.0.2
Built: 2024-09-25 15:18:20 UTC
Source: https://github.com/christopherkenny/planscorer

Help Index


Check or Get PlanScore API Key

Description

Check or Get PlanScore API Key

Usage

ps_has_key()

ps_get_key()

Value

logical if has, key invisibly if get

Examples

ps_has_key()

Capture PlanScore Graphs

Description

Capture PlanScore Graphs

Usage

ps_capture(link, path)

Arguments

link

plan_url output from ps_upload() functions

path

path to save copy of graphs in, likely ending in .png

Value

path to screenshot

Examples

# often times out
url <- 'https://planscore.org/plan.html?20221127T213653.168557156Z'
tf <- tempfile(fileext = '.png')
ps_capture(url, path = tf)

Ingest PlanScore Output

Description

Ingest PlanScore Output

Usage

ps_ingest(link)

Arguments

link

index url output from ps_upload() functions

Value

tibble with district and plan level data

Examples

url <- 'https://planscore.s3.amazonaws.com/uploads/20221127T213653.168557156Z/index.json'
ps_ingest(url)

List Model Versions

Description

List Model Versions

Usage

ps_model_versions()

Value

tibble of model versions

Examples

ps_model_versions()

Save PlanScore Output

Description

Save PlanScore Output

Usage

ps_save(link, path, json = TRUE)

Arguments

link

index url output from ps_upload() functions

path

path to save copy of data in, likely ending in .json if json = TRUE or .tsv if json = FALSE.

json

should the file be saved as .json (TRUE) or .tsv (FALSE). json = TRUE is slower but contains more information.

Value

path to json file

Examples

url <- 'https://planscore.s3.amazonaws.com/uploads/20221127T213653.168557156Z/index.json'
tf <- tempfile(fileext = '.json')
try({ # relies on internet resource
  ps_save(url, tf)
})

Add Entry to Renviron

Description

Adds PlanScore API key to .Renviron.

Usage

ps_set_key(key, overwrite = FALSE, install = FALSE)

Arguments

key

Character. API key to add to add.

overwrite

Defaults to FALSE. Boolean. Should existing PLANSCORE_KEY in Renviron be overwritten?

install

Defaults to FALSE. Boolean. Should this be added '~/.Renviron' file?

Value

key, invisibly

Examples

## Not run: 
set_planscore_key('1234')

## End(Not run)

List Currently Supported States

Description

List Currently Supported States

Usage

ps_supported_states()

Value

tibble of supported states

Examples

ps_supported_states()

Upload to PlanScore

Description

Upload to PlanScore

Usage

ps_upload_file(
  file,
  description = NULL,
  incumbents = NULL,
  model_version = NULL,
  library_metadata = NULL,
  temporary = TRUE
)

ps_upload_redist(map, plans, draw, ...)

ps_upload_shp(shp, ...)

Arguments

file

file to upload, one of a geojson, block assignment file, or zipped shape file

description

text for plan description

incumbents

Incumbent party, one of 'D' (Democrat), 'R' (Republican), or 'O' (Open) for each district. Assumes 'O' if none is provided.#'

model_version

character model version to use. Available options are listed by ps_model_versions().

library_metadata

Any additional data to be passed through for possible later use. For advanced use: Should likely be left NULL.

temporary

Should a temporary PlanScore upload be used? Default is TRUE.

map

a redist_map object

plans

a redist_plans object

draw

the draw to use from plans

...

arguments to pass on to ps_upload_file()

shp

an sf shape to upload, where each entry is a district

Value

list of links to index and plan, on success

Examples

# Requires API Key
file <- system.file('extdata/null-plan-incumbency.geojson', package = 'planscorer')
ps_upload_file(file)