The micromort package includes a full REST API with 30 endpoints for accessing risk data programmatically. The API is built with plumber and returns JSON with a standard response envelope.
Launch the API from R:
library(micromort)
launch_api()
#> ── Micromort Data API ──
#> ℹ Starting server at http://127.0.0.1:8080
#> ℹ Swagger docs: http://127.0.0.1:8080/__docs__/The interactive Swagger UI at /__docs__/ lets you explore all endpoints, view parameter descriptions, and try requests directly in the browser.
Every endpoint returns a standard JSON envelope:
{
"data": [ ... ],
"meta": {
"source": "micromort v0.4.0",
"endpoint": "/v1/risks/acute",
"n_rows": 10,
"timestamp": "2026-03-09T12:00:00Z",
"params": { "category": "Medical" }
}
}The data field contains the result (array or object). The meta field includes package version, endpoint path, row count, ISO 8601 timestamp, and the query parameters used.
Retrieve enriched acute risk data with optional filtering by category, minimum micromort threshold, and result limit.
curl "http://localhost:8080/v1/risks/acute?category=Medical&limit=10"show_target("vig_api_acute_sample")Query chronic lifestyle factors that gain or lose microlives per day.
curl "http://localhost:8080/v1/risks/chronic?direction=gain"show_target("vig_api_chronic_gains")Cancer mortality by type, sex, and age group with family history multipliers.
curl "http://localhost:8080/v1/risks/cancer?age_group=All%20ages"show_target("vig_api_cancer_top3")Find activities with equivalent risk to a reference activity. The response includes the ratio (how many of the reference activity equals one of each comparison activity).
curl "http://localhost:8080/v1/analysis/equivalence?reference=Chest+X-ray+(radiation+per+scan)"show_target("vig_api_equivalence_sample")Build a cross-comparison matrix for multiple activities. This is a POST endpoint that accepts a JSON body with an optional activities array:
curl -X POST "http://localhost:8080/v1/analysis/exchange-matrix" \
-H "Content-Type: application/json" \
-d '{"activities": ["Skiing", "Scuba diving, trained", "Skydiving (US)"]}'Convert between probability, micromorts, microlives, and loss of life expectancy.
# Probability to micromorts
curl "http://localhost:8080/v1/convert/to-micromort?prob=0.000001"
# Micromorts to probability
curl "http://localhost:8080/v1/convert/to-probability?micromorts=1"
# Loss of life expectancy (minutes)
curl "http://localhost:8080/v1/convert/lle?prob=0.00001&life_expectancy=40"
# Monetary value of a micromort (default VSL = $10M)
curl "http://localhost:8080/v1/convert/value?vsl=10000000"show_target("vig_api_conversion_table")Calculate daily micromort exposure from background mortality at any age, using Gompertz-Makeham mortality models.
curl "http://localhost:8080/v1/convert/hazard-rate?age=50&sex=female"show_target("vig_api_hazard_ages")All 30 API endpoints with their HTTP method, path, description, and parameters:
show_target("vig_api_endpoint_summary")You can call the API from R using httr2:
library(httr2)
base_url <- "http://localhost:8080"
# GET request with query parameters
resp <- request(base_url) |>
req_url_path("/v1/risks/acute") |>
req_url_query(category = "Sport", limit = 5) |>
req_perform() |>
resp_body_json()
# The data lives in resp$data
tibble::as_tibble(do.call(rbind, lapply(resp$data, as.data.frame)))
# POST request with JSON body
resp <- request(base_url) |>
req_url_path("/v1/analysis/exchange-matrix") |>
req_body_json(list(
activities = c("Skiing", "Scuba diving, trained")
)) |>
req_perform() |>
resp_body_json()sessionInfo()
R version 4.6.1 (2026-06-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 26.04 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DT_0.34.0 targets_1.12.0 micromort_0.2.0
loaded via a namespace (and not attached):
[1] base64url_1.4 jsonlite_2.0.0 compiler_4.6.1 tidyselect_1.2.1
[5] Rcpp_1.1.1-1.1 jquerylib_0.1.4 callr_3.8.0 yaml_2.3.12
[9] fastmap_1.2.0 R6_2.6.1 igraph_2.3.3 knitr_1.51
[13] htmlwidgets_1.6.4 backports_1.5.1 tibble_3.3.1 units_1.0-1
[17] maketools_1.3.2 rprojroot_2.1.1 bslib_0.11.0 pillar_1.11.1
[21] rlang_1.2.0 cachem_1.1.0 xfun_0.59 sass_0.4.10
[25] sys_3.4.3 otel_0.2.0 cli_3.6.6 magrittr_2.0.5
[29] crosstalk_1.2.2 ps_1.9.3 digest_0.6.39 processx_3.9.0
[33] secretbase_1.3.0 lifecycle_1.0.5 prettyunits_1.2.0 vctrs_0.7.3
[37] evaluate_1.0.5 glue_1.8.1 data.table_1.18.4 codetools_0.2-20
[41] buildtools_1.0.0 rmarkdown_2.31 tools_4.6.1 pkgconfig_2.0.3
[45] htmltools_0.5.9