lmr
lmr is a native LMScript host for distributions, statistical tests, regression, time series, clustering, smoothing, and numerical optimization. It is a small C++17 executable that needs no R runtime, and lmscript can install it automatically from a release.
Install and run
npm install -g @lmctl-ai/lmctl
lmscript --check analysis.lms
lmscript analysis.lms
lmr --version
lmr --lmcode-schema --json
A block that declares install="github:lmctl-ai/lmr@latest" lets lmscript download the release binary when lmr is not on PATH. A host already on PATH is used as is.
Host protocol
| Command | Effect |
|---|---|
| lmr --version | Prints lmr and the release version. |
| lmr --lmcode-schema | Prints a readable summary of every function, type and method. |
| lmr --lmcode-schema --json | Writes the embedded schema JSON that lmscript compiles against. |
| lmr --lmcode-signatures | Prints one canonical signature per line. |
| lmr --lmcode FILE.dslb [FILE ...] | Runs compiled programs; run_lmcode does this for you. |
| Exit code | Meaning |
|---|---|
| 0 | Success, all out.check assertions passed. |
| 2 | Command-line usage error. |
| 3 | Load or run error. |
| 4 | Application failure such as a failed check. |
Main objects and functions
The schema has one context object, 166 functions and 50 types. The table lists the entry points used most; the reference lists every signature.
| Area | Names | Notes |
|---|---|---|
| Context object out (type Out) | out.set, out.check, out.check_close, out.fail, out.failures, out.print | out.set exports a value into result.values; a failed check makes the run exit 4; out.print writes to stderr. |
| Vectors and frames | parse_vec, seq, frame, str_list; Vec supports + - * with vectors and numbers | parse_vec reads numeric text including NA, NaN, Inf and -Inf. |
| Distributions and random values | norm and the other Dist constructors, rng, Vec quantiles | Seed the Rng for reproducible draws. |
| Tests and models | test, lm, glm, nls, anova | Formulas are parsed by the native formula parser, not evaluated as R. |
| Time series | fft, arima, arima_sim, stl, Vec acf and pacf | |
| Smoothing and interpolation | smooth_spline, loess, spline_fun, approx_fun | |
| Clustering | kmeans, hclust | |
| Numerical methods | minimize, optimize, uniroot, integrate | Objectives are written in the block and fed to the solver object. |
| Standard library | lmcode_std_v3, 206 signatures as vendored | The current upstream catalog has 226 signatures including the REST and CLI interfaces; lmr does not vendor those yet. |
Minimal example
Save as linear-fit.lms and run it with lmscript. This is the linear fit example from the lmr repository and compiles with lmscript --check.
p = _lmcode_ cli="lmr" install="github:lmctl-ai/lmr@latest";
let x = seq(0.0, 5.0, 1.0);
let fit = lm(frame().set("x", x).set("y", 2.0 * x + 1.0), "y ~ x");
out.check_close(fit.estimates().at(0), 1.0, 0.000000000001, "intercept is 1");
out.check_close(fit.estimates().at(1), 2.0, 0.000000000001, "slope is 2");
out.set("intercept", fit.estimates().at(0));
out.set("slope", fit.estimates().at(1));
end _lmcode_
r = run_lmcode(p);
require(r.ok, "run failed: " + r.get("message", "unknown"));
result = r.result;
println(sprintf("Line fit: intercept %.1f, slope %.1f", result.values.intercept, result.values.slope));
run_lmcode returns ok and result; for lmr the result holds values, checks and failures.
More
- The lmr skill: setup, safety rules and verification.
- The API guide: operations, results and limits.
- The reference: every flag, exit code, type, method and function.
- Get started: a solo or trio lmr quickrun that asks a provider team to analyze a small data set.
- The example book: runnable analyses.
- github.com/lmctl-ai/lmr: source and releases.