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

CommandEffect
lmr --versionPrints lmr and the release version.
lmr --lmcode-schemaPrints a readable summary of every function, type and method.
lmr --lmcode-schema --jsonWrites the embedded schema JSON that lmscript compiles against.
lmr --lmcode-signaturesPrints one canonical signature per line.
lmr --lmcode FILE.dslb [FILE ...]Runs compiled programs; run_lmcode does this for you.
Exit codeMeaning
0Success, all out.check assertions passed.
2Command-line usage error.
3Load or run error.
4Application 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.

AreaNamesNotes
Context object out (type Out)out.set, out.check, out.check_close, out.fail, out.failures, out.printout.set exports a value into result.values; a failed check makes the run exit 4; out.print writes to stderr.
Vectors and framesparse_vec, seq, frame, str_list; Vec supports + - * with vectors and numbersparse_vec reads numeric text including NA, NaN, Inf and -Inf.
Distributions and random valuesnorm and the other Dist constructors, rng, Vec quantilesSeed the Rng for reproducible draws.
Tests and modelstest, lm, glm, nls, anovaFormulas are parsed by the native formula parser, not evaluated as R.
Time seriesfft, arima, arima_sim, stl, Vec acf and pacf
Smoothing and interpolationsmooth_spline, loess, spline_fun, approx_fun
Clusteringkmeans, hclust
Numerical methodsminimize, optimize, uniroot, integrateObjectives are written in the block and fed to the solver object.
Standard librarylmcode_std_v3, 206 signatures as vendoredThe 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