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-11-24 05:56:31 UTC |
Source: | https://github.com/christopherkenny/planscorer |
Check or Get PlanScore API Key
ps_has_key() ps_get_key()
ps_has_key() ps_get_key()
logical if has
, key invisibly if get
ps_has_key()
ps_has_key()
Capture PlanScore Graphs
ps_capture(link, path)
ps_capture(link, path)
link |
plan_url output from |
path |
path to save copy of graphs in, likely ending in |
path to screenshot
# often times out url <- 'https://planscore.org/plan.html?20221127T213653.168557156Z' tf <- tempfile(fileext = '.png') ps_capture(url, path = tf)
# often times out url <- 'https://planscore.org/plan.html?20221127T213653.168557156Z' tf <- tempfile(fileext = '.png') ps_capture(url, path = tf)
Ingest PlanScore Output
ps_ingest(link)
ps_ingest(link)
link |
index url output from |
tibble
with district and plan level data
url <- 'https://planscore.s3.amazonaws.com/uploads/20221127T213653.168557156Z/index.json' ps_ingest(url)
url <- 'https://planscore.s3.amazonaws.com/uploads/20221127T213653.168557156Z/index.json' ps_ingest(url)
List Model Versions
ps_model_versions()
ps_model_versions()
tibble of model versions
ps_model_versions()
ps_model_versions()
Save PlanScore Output
ps_save(link, path, json = TRUE)
ps_save(link, path, json = TRUE)
link |
index url output from |
path |
path to save copy of data in, likely ending in |
json |
should the file be saved as |
path to json
file
url <- 'https://planscore.s3.amazonaws.com/uploads/20221127T213653.168557156Z/index.json' tf <- tempfile(fileext = '.json') try({ # relies on internet resource ps_save(url, tf) })
url <- 'https://planscore.s3.amazonaws.com/uploads/20221127T213653.168557156Z/index.json' tf <- tempfile(fileext = '.json') try({ # relies on internet resource ps_save(url, tf) })
Adds PlanScore API key to .Renviron.
ps_set_key(key, overwrite = FALSE, install = FALSE)
ps_set_key(key, overwrite = FALSE, install = FALSE)
key |
Character. API key to add to add. |
overwrite |
Defaults to FALSE. Boolean. Should existing |
install |
Defaults to FALSE. Boolean. Should this be added '~/.Renviron' file? |
key, invisibly
## Not run: set_planscore_key('1234') ## End(Not run)
## Not run: set_planscore_key('1234') ## End(Not run)
List Currently Supported States
ps_supported_states()
ps_supported_states()
tibble of supported states
ps_supported_states()
ps_supported_states()
Upload to PlanScore
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, ...)
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, ...)
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 |
model_version |
character model version to use. Available options are listed by |
library_metadata |
Any additional data to be passed through for possible later use.
For advanced use: Should likely be left |
temporary |
Should a temporary PlanScore upload be used? Default is TRUE. |
map |
a |
plans |
a |
draw |
the draw to use from |
... |
arguments to pass on to |
shp |
an |
list of links to index and plan, on success
# Requires API Key file <- system.file('extdata/null-plan-incumbency.geojson', package = 'planscorer') ps_upload_file(file)
# Requires API Key file <- system.file('extdata/null-plan-incumbency.geojson', package = 'planscorer') ps_upload_file(file)