Download r/plumber.R from mnoorchenar/StatAgent: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/datasets/mnoorchenar/StatAgent/resolve/main/r/plumber.R
- Command line
-
hf download hf://datasets/mnoorchenar/StatAgent/r/plumber.R
-
curl -L -o plumber.R https://huggingface.co/datasets/mnoorchenar/StatAgent/resolve/main/r/plumber.R
1.22 kB
| # plumber API exposing validated stat tools. Run: Rscript r/run_api.R | |
| .d <- Sys.getenv("STATAGENT_R_DIR", "r/R"); suppressMessages(for (f in list.files(.d, full.names = TRUE)) source(f)) | |
| num <- function(x) as.numeric(vapply(x, function(z) if (is.null(z)) NA_real_ else as.numeric(z), numeric(1))) | |
| wrap <- function(expr) tryCatch(expr, error = function(e) list(error = conditionMessage(e))) | |
| #* @get /health | |
| function() list(status = "ok") | |
| #* @serializer json list(auto_unbox = TRUE, na = "null", digits = 6) | |
| #* @post /drift | |
| function(req) wrap({ b <- req$body; detect_drift(num(b$values), baseline_n = b$baseline_n %||% 100) }) | |
| #* @serializer json list(auto_unbox = TRUE, na = "null", digits = 6) | |
| #* @post /dose_response | |
| function(req) wrap({ b <- req$body; fit_dose_response(unlist(b$dose), unlist(b$response)) }) | |
| #* @serializer json list(auto_unbox = TRUE, na = "null", digits = 6) | |
| #* @post /batch_variance | |
| function(req) wrap({ b <- req$body | |
| batch_variance(data.frame(batch = unlist(b$group), strength = unlist(b$values))) }) | |
| #* @serializer json list(auto_unbox = TRUE, na = "null", digits = 6) | |
| #* @post /power | |
| function(req) wrap({ b <- req$body; power_two_means(b$delta, b$sd, b$power %||% 0.8, b$alpha %||% 0.05) }) | |