| Title: | Carceral, Policing, and Public-Health Data Retrieval and Analysis |
|---|---|
| Description: | A focused interface for retrieving, mining, and analysing open carceral, policing, police-oversight, and public-health data. Covers correctional tracking (OTIS), municipal police services (Toronto, New York, Chicago, Vancouver), special-investigations and oversight bodies (SIU, ARSAU), and substance-use surveys (Canadian Cannabis Survey, CPADS, and related Health Infobase and CIHI tables). Provides polite, cache-aware fetchers and re-exports the focused domain analysis API (causal estimators, survey weighting, fairness audits, spatial statistics, item-response models) from the upstream 'rmorie' toolkit. |
| Authors: | Vansh Singh Ruhela [aut, cre] (ORCID: <https://orcid.org/0009-0004-1750-3592>) |
| Maintainer: | Vansh Singh Ruhela <[email protected]> |
| License: | AGPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-06-24 20:37:07 UTC |
| Source: | https://github.com/rootcoder007/rmorielite |
Returns the directory rmorielite uses for cached resources. By
default this is a sub-tree of the R session temporary directory
(tempdir()) — files are cleaned up automatically when R exits, in
line with the CRAN policy that packages must not write outside the
session temp area without explicit user consent.
rmorielite_cache_dir( which = c("cache", "data", "config"), create = TRUE, persistent = NULL )rmorielite_cache_dir( which = c("cache", "data", "config"), create = TRUE, persistent = NULL )
which |
One of |
create |
Logical. If |
persistent |
Logical or |
To opt in to a persistent cache that survives R sessions, set the
environment variable RMORIELITE_PERSISTENT_CACHE=1 or pass
persistent = TRUE. The persistent location follows R's official
convention via tools::R_user_dir() — on macOS that is
~/Library/Application Support/.../rmorielite, on Windows
%LOCALAPPDATA%\R\.../rmorielite, and on Linux
$XDG_DATA_HOME/R/rmorielite (or ~/.local/share/R/rmorielite if
XDG_DATA_HOME is unset).
A character scalar: the absolute path of the directory.
rmorielite_cache_dir() # default: session tempdir rmorielite_cache_dir(persistent = TRUE) # opt in to R_user_dirrmorielite_cache_dir() # default: session tempdir rmorielite_cache_dir(persistent = TRUE) # opt in to R_user_dir
Queries a CKAN open-data portal's package_show endpoint and
returns metadata for the first resource whose name field
matches a supplied regular expression. CKAN powers many government
open-data portals (Ontario, UK, Canada, US federal); resource UUIDs
occasionally change between portal updates but resource names are
usually stable, so name-pattern matching survives portal reslugs.
rmorielite_ckan_resolve(portal, package_slug, name_pattern, timeout = 30)rmorielite_ckan_resolve(portal, package_slug, name_pattern, timeout = 30)
portal |
Base URL of the CKAN portal, without trailing slash.
Example: |
package_slug |
CKAN package slug. Example:
|
name_pattern |
PCRE-compatible regex applied case-insensitively
to each resource's |
timeout |
Request timeout in seconds. Default |
A list with elements name, url, format, resource_id,
and package_slug, or NULL if the package is not found, the API
call fails, or no resource matches.
res <- rmorielite_ckan_resolve( portal = "https://data.ontario.ca", package_slug = "data-on-inmates-in-ontario", name_pattern = "Restrictive.?Confinement.*Detailed.?Dataset" ) if (!is.null(res)) res$urlres <- rmorielite_ckan_resolve( portal = "https://data.ontario.ca", package_slug = "data-on-inmates-in-ontario", name_pattern = "Restrictive.?Confinement.*Detailed.?Dataset" ) if (!is.null(res)) res$url
Downloads a single URL to the per-user cache directory (see
rmorielite_cache_dir()) using httr2 with built-in throttling
and exponential-backoff retry on 429/5xx. If a non-empty cached
copy at the same target path already exists, the download is
skipped and the cached path is returned.
rmorielite_fetch( url, dest_basename = NULL, rate = 4, force = FALSE, max_tries = 3L )rmorielite_fetch( url, dest_basename = NULL, rate = 4, force = FALSE, max_tries = 3L )
url |
The URL to fetch. |
dest_basename |
Filename (no path) under which to cache the result. Defaults to the URL's basename. |
rate |
Requests per second. Default |
force |
If |
max_tries |
Maximum retry attempts on transient errors
(429, 5xx). Default |
Throttling and retry are delegated to httr2::req_throttle() and
httr2::req_retry(). The default rate cap of 4 requests per
second matches the polite-by-default conventions used by major
public-data CKAN portals.
A character scalar: the absolute path of the cached file.
path <- rmorielite_fetch( "https://data.ontario.ca/api/3/action/package_list" ) file.exists(path)path <- rmorielite_fetch( "https://data.ontario.ca/api/3/action/package_list" ) file.exists(path)