Title: | Score Redistricting Plans with 'PlanScore' |
Version: | 0.0.2 |
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. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2.9000 |
Imports: | cli, curl, dplyr, fs, httr2, jsonlite, purrr, readr, rlang, sf, stringr, tibble, tidyr, webshot2 |
URL: | http://christophertkenny.com/planscorer/, https://github.com/christopherkenny/planscorer |
BugReports: | https://github.com/christopherkenny/planscorer/issues |
Suggests: | httptest2, spelling, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Language: | en-US |
NeedsCompilation: | no |
Packaged: | 2024-09-24 14:38:45 UTC; chris |
Author: | Christopher T. Kenny
|
Maintainer: | Christopher T. Kenny <christopherkenny@fas.harvard.edu> |
Repository: | CRAN |
Date/Publication: | 2024-09-24 14:50:02 UTC |
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 |
path |
path to save copy of graphs in, likely ending in |
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 |
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 |
path |
path to save copy of data in, likely ending in |
json |
should the file be saved as |
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 |
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 |
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 |
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)