Skip to content

docs: Improved transpiler documentation#358

Merged
mhovd merged 1 commit into
mainfrom
transpiler-documentation
Jun 23, 2026
Merged

docs: Improved transpiler documentation#358
mhovd merged 1 commit into
mainfrom
transpiler-documentation

Conversation

@mhovd

@mhovd mhovd commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Now clearly lists all (currently) supported operations, and gives an informative error when a non-supported function/operation is used, e.g.

R input: `y[1] <- median(x[1])`
✖ Failed to transpile:
✖ Unsupported function "median" in model block.
ℹ The model transpiler does not know how to convert "median" to Rust. ℹ Supported functions and operators are:
• Grouping/structure: (, {, if, else, for, <-, =, [ ] (indexing) • Arithmetic: +, -, *, /, ^
• Comparison: ==, !=, >=, <=, >, <
• Logical: &, |, !
• Math: abs, exp, sqrt, ln, log, log10, log2
• Trigonometric: sin, cos, tan, asin, acos, atan, atan2 • Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh • Rounding: floor, ceiling, round, trunc
• Pmetrics helpers: get_e2

Now clearly lists all (currently) supported operations, and gives an informative error when a non-supported function/operation is used, e.g.

R input: `y[1] <- median(x[1])`
✖ Failed to transpile:
✖ Unsupported function "median" in model block.
ℹ The model transpiler does not know how to convert "median" to Rust.
ℹ Supported functions and operators are:
• Grouping/structure: (, {, if, else, for, <-, =, [ ] (indexing)
• Arithmetic: +, -, *, /, ^
• Comparison: ==, !=, >=, <=, >, <
• Logical: &, |, !
• Math: abs, exp, sqrt, ln, log, log10, log2
• Trigonometric: sin, cos, tan, asin, acos, atan, atan2
• Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh
• Rounding: floor, ceiling, round, trunc
• Pmetrics helpers: get_e2

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the R-to-Rust model-block transpiler’s user-facing documentation and error reporting by explicitly cataloguing supported operators/functions and emitting a detailed cli_abort() message when unsupported syntax is encountered.

Changes:

  • Added an in-file, categorized list of supported R functions/operators for model blocks.
  • Introduced supported_transpiler_ops() + abort_unsupported_op() to generate a more informative unsupported-operation error.
  • Updated expr_to_rust() to use the new error helper instead of a generic stop().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/model_transpiler.R
Comment on lines +69 to +74
operators <- c(
ops$Arithmetic, ops$Comparison, ops$Logical,
"(", "{", "if", "else", "for", "<-", "=", "[ ]"
)
is_operator <- op %in% operators
kind <- if (is_operator) "operator" else "function"
Comment thread R/model_transpiler.R
Comment on lines +368 to 369
abort_unsupported_op(op)
)
@mhovd mhovd merged commit dee0cbf into main Jun 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants